简体   繁体   English

wp_remote_get函数响应未显示预期结果

[英]wp_remote_get function response not showing intended result

I have not made WordPress http request before this. 我之前没有发过WordPress http请求。 I did it first time and I am not getting the return response. 我第一次这样做了,我没有收到回复。 It seems the response is not the intended as the API I am using, there the documentation depicts some parameters we can get in return, but I cant find any of those parameter in the response. 似乎响应不是我正在使用的API的目标,文档描述了我们可以获得的一些参数,但我无法在响应中找到任何这些参数。

Here is my test code: 这是我的测试代码:

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

The above code generating the following output: 上面的代码生成以下输出:

( [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

Can someone please explain what does the above response actually mean? 有人可以解释一下上面的反应究竟是什么意思吗?

This is my first time using WordPress HTTP request sending, so I am quite confused. 这是我第一次使用WordPress HTTP请求发送,所以我很困惑。

It is an array. 这是一个数组。 It provides information on how the data is sent. 它提供有关数据发送方式的信息。 Look at the [headers] and you'll find information about the content-type, the charset, the connection etc.. The [headers][content-type] for instance indicates on how you can proceed with the information. 查看[headers],你会找到有关内容类型,字符集,连接等的信息。例如,[headers] [content-type]表示你如何处理这些信息。 And then the [body], the actual content, that you probably will use in some way. 然后你可能会以某种方式使用的[body],实际内容。 You can read it better, if you output like this: 如果输出如下,你可以更好地阅读它:

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

You can for instance just retrieve the [body]: 例如,您可以检索[body]:

$bodyX = $response1['body'];

You can, as before, print the result: 您可以像以前一样打印结果:

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

Good luck. 祝好运。

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

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