访问Wordpress REST API(本地主机)时服务器超时错误

时间:2019-10-10 22:21:08

标签: wordpress wordpress-rest-api

我试图访问我的帖子的REST API,然后将数据添加到特定帖子的REST API。

要测试并确保我能正确返回数据,我正在使用以下代码,然后查看页面源代码以确保我正在获得想要的东西:

    add_action('rest_api_init', function() {

  $response = wp_remote_get('http://localhost:8888/my-website/wp-json/wp/v2/posts');

  echo 'Beginning of response';
  var_dump($response);
  echo 'End of response';
});

执行此操作时,出现错误:

Beginning of responseobject(WP_Error)#752 (2) {
  ["errors"]=>
  array(1) {
    ["http_request_failed"]=>
    array(1) {
      [0]=>
      string(80) "cURL error 28: Operation timed out after 5000 milliseconds with 0 bytes received"
    }
  }
  ["error_data"]=>
  array(0) {
  }
}
End of response

但是我见过的每个引用都使用wp_remote_get的{​​{1}}或WP_REST_Request::from_url数据来GET

注意:我还对API中的第二个参数使用了以下代码作为$args,并且仍然得到相同的响应,但是响应时间为10000毫秒而不是5000毫秒:

wp_remote_get

哪个来自this question

0 个答案:

没有答案