微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

phpcUrl 不返回最新的 JSON 数据

如何解决phpcUrl 不返回最新的 JSON 数据

我对此感到困惑。我正在为特定的帖子 ID 使用简单的 wordpress REST 端点。

在我的 PHPcUrl 代码中,在对一个或多个自定义字段进行编辑后,我仍然从端点获取旧的 JSON 数据

    $endpoint = "https://www.yeahbuoy.com.au/wp-json/wp/v2/posts/1191";

    // Example of call to the API
    try
    {   
        // Get cURL resource
        $curl = curl_init();
        // Set some options 
        curl_setopt_array($curl,array(
        CURLOPT_RETURNTRANSFER => 1,CURLOPT_URL => $endpoint,CURLOPT_FRESH_CONNECT => 1,CURLOPT_HEADER => 0,CURLOPT_HTTPHEADER => ['Content-Type: application/json','Accept:application/json','Cache-Control: no-cache,no-store,must-revalidate','Pragma: no-cache','Expires: 0']
        ));
        // Send the request & save response to $resp
        $resp = curl_exec($curl);

        // Check HTTP status code
        if (!curl_errno($curl)) {
            switch ($http_code = curl_getinfo($curl,CURLINFO_HTTP_CODE)) {
                case 200:  # OK
                    //echo "<code>" . $resp ."</code>";
                    
                    $obj = json_decode($resp,true);
                    $html = "";
                    $html2 = "";
                    $html3 = "";

                    $html .= "<div class=\"center\"><img src='". $obj["acf"]["main_picture"]."' border=\"0\" class=\"responsive-img z-depth-2\"></div>\n";

                    $html2 .= "<ul class=\"collection\">\n";
                    
                    $html2 .= "<li class=\"collection-item center-align active black\"><i class=\"material-icons circle\">info</i>Event</li>\n";                    
                    $html2 .= "<li class=\"collection-item center-align\">". $obj["acf"]["event_name"]."</li>\n";
                    
                    $html2 .= "<li class=\"collection-item center-align active black\"><i class=\"material-icons circle\">map</i>  Where?</li>\n";
                    $html2 .= "<li class=\"collection-item center-align\">". $obj["acf"]["location"]."</li>\n";
                    
                    $html2 .= "<li class=\"collection-item center-align active black\"><i class=\"material-icons circle\">date_range</i>  When?</li>\n";
                    $html2 .= "<li class=\"collection-item center-align\">". $obj["acf"]["date_and_time"]."</li>\n";
                    $html2 .= "</ul>\n";

                    $html2 .= $obj["content"]["rendered"];

                    $galleryCount = 1;
                    //ACF has provision for 3 images
                    while ($galleryCount <= 3)
                    {
                        $galleryArray = "gallery_" .$galleryCount;
                        //If there is a photo for the gallery field then show it
                        if ($obj['acf'][$galleryArray]) 
                        {
                            $html3 .=  "<p><div class=\"center\"><img src='" . $obj["acf"][$galleryArray] ."' border=\"0\" width=\"340\" height =\"300\" class=\"responsive-img z-depth-2\"></div></p>\n";
                        }
                        $galleryCount++;
                    }
                    
           
                    break;
                default:
                    echo 'Unexpected HTTP code: ',$http_code,"\n";
                    echo $resp;
            }
        }
        
        // Close request to clear up some resources
        curl_close($curl);


    } catch (Exception $ex) {

        printf("Error while sending request,reason: %s\n",$ex->getMessage());

    }

如果我在浏览器中运行端点 URL,它是 JSON 中的更新数据,但在我的 PHP 代码执行时不是。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。