简体   繁体   English

服务不可用 REST API wordpress

[英]Service unavailable in REST API call from wordpress

From a basic installation of wordpress + woocommerce I created a custom plugin that calls an API in GET protocol with bearer token.从 wordpress + woocommerce 的基本安装中,我创建了一个自定义插件,它使用不记名令牌在 GET 协议中调用 API。 I copied the php curl code from postman and both locally and on postman I can connect to the rest service without problems.我从 postman 复制了 php curl 代码,在本地和 postman 上我都可以毫无问题地连接到 rest 服务。 But if I use the same code from wordpress, I get "503 Service Unavailable".但是,如果我使用来自 wordpress 的相同代码,我会得到“503 服务不可用”。 Not being an expert I don't know if the problem is due to an incorrect configuration of apache2 /.htacces file or if wordpress adds headers or other things that make the call fail in 503不是专家我不知道问题是由于 apache2 /.htacces 文件的配置不正确还是 wordpress 添加了标头或其他导致调用在 503 中失败的东西

I report here the call curl我在这里报告电话 curl

protected function getGetData($url,$token){
    $curl = curl_init();
    $auth= 'Authorization: Bearer '.$token;
    curl_setopt_array($curl, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'GET',
        CURLOPT_HTTPHEADER => array(
            $auth
        ),
    ));

    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
}

I have already tried turning off all wordpress plugins with no results.我已经尝试关闭所有 wordpress 插件,但没有结果。 the particular thing is that by changing some settings sometimes the call returns 200 the first time but from the second onwards it continues to return 503. From postman and local php instead it works every time the function is executed特别的是,通过更改某些设置,有时调用第一次返回 200,但从第二次开始它继续返回 503。从 postman 和本地 php 相反,每次执行 function 时它都有效

I did some checks and in these cases I noticed that it is advisable to first disable each plugin on the wordpress side and then, check that there are no controls by whoever supplies the API. In my case I found that the server had a call limit that I had exceeded and for which it was returning 503.我做了一些检查,在这些情况下,我注意到建议首先禁用 wordpress 端的每个插件,然后检查提供 API 的人是否没有控制。在我的例子中,我发现服务器有调用限制我已经超过了,为此它返回了 503。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM