【问题标题】:wp_remote_get function response not showing intended resultwp_remote_get 函数响应未显示预期结果
【发布时间】:2016-06-22 13:34:05
【问题描述】:

在此之前我没有发出过 WordPress http 请求。我是第一次这样做,但没有收到回复。似乎响应不是我正在使用的 API 的预期,文档描述了我们可以获得的一些参数作为回报,但我在响应中找不到任何这些参数。

这是我的测试代码:

$response1 = wp_remote_get('https://api.duoservers.com/?auth_usernme=theapiusername&auth_password=theapipassword&section=products&command=get_plans');
print_r($response1);

以上代码生成以下输出:

( [headers] => Array ( [server] => nginx [date] => Wed, 22 Jun 2016 08:34:50 GMT [content-type] => text/html; charset=UTF-8 [content-length] => 182 [connection] => close [vary] => Accept-Encoding [content-encoding] => gzip ) [body] => 0 1 0.017 s 0.004 s 6079653986 0 [response] => Array ( [code] => 200 [message] => OK ) [cookies] => Array ( ) [filename] => ) 0 1 0.016 s 0.005 s 6687868871 0

有人可以解释一下上述回复的实际含义吗?

这是我第一次使用WordPress HTTP请求发送,所以我很困惑。

【问题讨论】:

    标签: php wordpress http-request


    【解决方案1】:

    这是一个数组。它提供有关如何发送数据的信息。查看 [headers],您将找到有关内容类型、字符集、连接等的信息。例如,[headers][content-type] 指示您如何处理这些信息。然后是 [body],实际内容,您可能会以某种方式使用。如果您像这样输出,您可以更好地阅读它:

    echo '<pre>';
    print_r($resonse1); //you can also use var_dump()
    echo '</pre>';
    

    例如,您可以只检索 [body]:

    $bodyX = $response1['body'];
    

    您可以像以前一样打印结果:

    echo '<pre>';
    print_r($bodyX); //you can also use var_dump()
    echo '</pre>';
    

    祝你好运。

    【讨论】:

      猜你喜欢
      • 2022-08-14
      • 2021-04-14
      • 2011-10-02
      • 2019-04-05
      • 1970-01-01
      • 2022-01-20
      • 2022-08-19
      • 2017-06-08
      • 2018-12-16
      相关资源
      最近更新 更多