Wordpress 发送带有wp_remote_post的URL不工作
我正在使用一个接受此格式URL的服务Wordpress 发送带有wp_remote_post的URL不工作,wordpress,Wordpress,我正在使用一个接受此格式URL的服务 http://www.mydomain.com/zone1/code/verify/?data1=Apple&data1=Banana&data3=Orange&data4=Pear 我正在尝试使用wp_remote_post来提交它并收到响应 $url = 'http://www.mydomain.com/zone1/code/verify/'; $fields = array(); $fields['da
http://www.mydomain.com/zone1/code/verify/?data1=Apple&data1=Banana&data3=Orange&data4=Pear
我正在尝试使用wp_remote_post来提交它并收到响应
$url = 'http://www.mydomain.com/zone1/code/verify/';
$fields = array();
$fields['data1'] = 'Apple';
$fields['data2'] = 'Banana';
$fields['data3'] = 'Orange';
$fields['data4'] = 'Pear';
$response = wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => $fields,
'cookies' => array()
)
);
这不起作用,我收到的回复是字段丢失
有人能看出我的方法有什么问题吗?有没有一种简单的方法可以准确地回显它发送的URL?此URL:
http://www..../verify/?data1=Apple&data1=Banana&data3=Orange&data4=Pear
是GET格式,不是POST格式,因此您应该检查该请求的API文档,但它可能不支持POST格式,因此您需要使用GET语法,如下所示:
$url = 'http://www.mydomain.com/zone1/code/verify/';
$url .= '?data1=Apple';
$url .= '&data2=Banana';
$url .= '&data3=Orange';
$url .= '&data4=Pear';
$args = array(); //the default arguments should be ok unless the API needs something special like authentication headers
$response = wp_remote_get($url, $args);
我喜欢使用插件来挖掘像这样的输出,使用它可以调用dd($response)
并获得格式良好的响应显示。如果没有该插件,只需在之后添加以下内容:
print '<pre>';
print_r($repsonse);
die();
打印“”;
打印(repsonse);
模具();
这应该显示响应变量中的所有内容。感谢您的解释,这一切都是有意义的。我现在就去申请