Php 将CURL请求转换为Wordpress wp_remote_post
我需要将PHP库从CURL转换为wp_remote_post,以用于Wordpress插件 我有参考资料 这是我试图转换的代码Php 将CURL请求转换为Wordpress wp_remote_post,php,curl,wordpress,Php,Curl,Wordpress,我需要将PHP库从CURL转换为wp_remote_post,以用于Wordpress插件 我有参考资料 这是我试图转换的代码 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $scheme . $url['host'] . $url['path']); curl_setopt($ch, CURLOPT_PORT, $port); curl_setopt($ch, CURLOPT_SSL_VERI
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $scheme . $url['host'] . $url['path']);
curl_setopt($ch, CURLOPT_PORT, $port);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_USERAGENT, $this->_config['UserAgent']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = "";
$response = curl_exec($ch);
if ($response === false) {
$errorResponse = curl_error($ch);
require_once("FBAOutboundServiceMWS/Exception.php");
curl_close($ch);
throw new FBAOutboundServiceMWS_Exception(array(
'Message' => $errorResponse,
'ErrorType' => 'HTTP'
));
}
curl_close($ch);
这是我“认为”是正确的,但不起作用
$THEurl = $scheme . $url['host'] . $url['path'];
$response = wp_remote_post( $THEurl, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => $query,
'cookies' => array()
)
);
if ( is_wp_error( $response ) ) {
$errorResponse = $response->get_error_message();
require_once("FBAOutboundServiceMWS/Exception.php");
curl_close($ch);
throw new FBAOutboundServiceMWS_Exception(array(
'Message' => $errorResponse,
'ErrorType' => 'HTTP'
));
}
wp\u remote\u post
实际上是在什么时候执行的?就在函数被调用的时候?
(非常感谢您的事先帮助;) 帮我试试这个,看看你能得到什么回报
$THEurl = $scheme . $url['host'] . $url['path'];
$response = wp_remote_post( $THEurl, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => $query,
'cookies' => array()
)
);
if ( is_wp_error( $response ) ) {
$errorResponse = $response->get_error_message();
require_once("FBAOutboundServiceMWS/Exception.php");
throw new FBAOutboundServiceMWS_Exception(
array(
'Message' => $errorResponse,
'ErrorType' => 'HTTP'
)
);
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}
$THEurl=$scheme$url['host']$url['path'];
$response=wp\u remote\u post($THEurl,数组(
'方法'=>'发布',
“超时”=>45,
“重定向”=>5,
'httpversion'=>'1.0',
“阻塞”=>正确,
'headers'=>array(),
“body”=>$query,
'cookies'=>array()
)
);
如果(是错误($response)){
$errorResponse=$response->get_error_message();
需要一次(“FBAOutboundServiceMWS/Exception.php”);
抛出新的FBAOutboundServiceMWS\u异常(
排列(
'Message'=>$errorResponse,
'ErrorType'=>'HTTP'
)
);
}否则{
回应"回应";;
打印(回复);
回声';
}
取出您不需要的代码,并在打印响应时添加了您以前没有做过的操作。请为我尝试一下,看看您得到了什么
$THEurl = $scheme . $url['host'] . $url['path'];
$response = wp_remote_post( $THEurl, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => $query,
'cookies' => array()
)
);
if ( is_wp_error( $response ) ) {
$errorResponse = $response->get_error_message();
require_once("FBAOutboundServiceMWS/Exception.php");
throw new FBAOutboundServiceMWS_Exception(
array(
'Message' => $errorResponse,
'ErrorType' => 'HTTP'
)
);
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}
$THEurl=$scheme$url['host']$url['path'];
$response=wp\u remote\u post($THEurl,数组(
'方法'=>'发布',
“超时”=>45,
“重定向”=>5,
'httpversion'=>'1.0',
“阻塞”=>正确,
'headers'=>array(),
“body”=>$query,
'cookies'=>array()
)
);
如果(是错误($response)){
$errorResponse=$response->get_error_message();
需要一次(“FBAOutboundServiceMWS/Exception.php”);
抛出新的FBAOutboundServiceMWS\u异常(
排列(
'Message'=>$errorResponse,
'ErrorType'=>'HTTP'
)
);
}否则{
回应"回应";;
打印(回复);
回声';
}
取出您不需要的代码,并在打印响应时添加了您以前没有做过的操作。请为我尝试一下,看看您得到了什么
$THEurl = $scheme . $url['host'] . $url['path'];
$response = wp_remote_post( $THEurl, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => $query,
'cookies' => array()
)
);
if ( is_wp_error( $response ) ) {
$errorResponse = $response->get_error_message();
require_once("FBAOutboundServiceMWS/Exception.php");
throw new FBAOutboundServiceMWS_Exception(
array(
'Message' => $errorResponse,
'ErrorType' => 'HTTP'
)
);
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}
$THEurl=$scheme$url['host']$url['path'];
$response=wp\u remote\u post($THEurl,数组(
'方法'=>'发布',
“超时”=>45,
“重定向”=>5,
'httpversion'=>'1.0',
“阻塞”=>正确,
'headers'=>array(),
“body”=>$query,
'cookies'=>array()
)
);
如果(是错误($response)){
$errorResponse=$response->get_error_message();
需要一次(“FBAOutboundServiceMWS/Exception.php”);
抛出新的FBAOutboundServiceMWS\u异常(
排列(
'Message'=>$errorResponse,
'ErrorType'=>'HTTP'
)
);
}否则{
回应"回应";;
打印(回复);
回声';
}
取出您不需要的代码,并在打印响应时添加了您以前没有做过的操作。请为我尝试一下,看看您得到了什么
$THEurl = $scheme . $url['host'] . $url['path'];
$response = wp_remote_post( $THEurl, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => $query,
'cookies' => array()
)
);
if ( is_wp_error( $response ) ) {
$errorResponse = $response->get_error_message();
require_once("FBAOutboundServiceMWS/Exception.php");
throw new FBAOutboundServiceMWS_Exception(
array(
'Message' => $errorResponse,
'ErrorType' => 'HTTP'
)
);
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}
$THEurl=$scheme$url['host']$url['path'];
$response=wp\u remote\u post($THEurl,数组(
'方法'=>'发布',
“超时”=>45,
“重定向”=>5,
'httpversion'=>'1.0',
“阻塞”=>正确,
'headers'=>array(),
“body”=>$query,
'cookies'=>array()
)
);
如果(是错误($response)){
$errorResponse=$response->get_error_message();
需要一次(“FBAOutboundServiceMWS/Exception.php”);
抛出新的FBAOutboundServiceMWS\u异常(
排列(
'Message'=>$errorResponse,
'ErrorType'=>'HTTP'
)
);
}否则{
回应"回应";;
打印(回复);
回声';
}
取出了您不需要的代码,并在打印响应时添加了您以前没有做过的操作。非常有用-。-@HoboDo您有错误代码吗?错误日志中是否显示任何内容?我看不出你做的有什么不对。
$query
变量中有什么?另外,我也不太清楚为什么你在错误区域运行curl_close()。非常有用-。-@HoboDo你有错误代码吗?错误日志中是否显示任何内容?我看不出你做的有什么不对。$query
变量中有什么?另外,我也不太清楚为什么你在错误区域运行curl_close()。非常有用-。-@HoboDo你有错误代码吗?错误日志中是否显示任何内容?我看不出你做的有什么不对。$query
变量中有什么?另外,我也不太清楚为什么你在错误区域运行curl_close()。非常有用-。-@HoboDo你有错误代码吗?错误日志中是否显示任何内容?我看不出你做的有什么不对。$query
变量中有什么?我也不太清楚为什么你在错误区域运行curl\u close()。这让我找到了我的答案,wp\u remote\u post
以数组形式返回了我的数据,所以我不得不改变返回答案的使用方式。感谢您的帮助。这让我找到了我的答案,wp\u remote\u post
以数组形式返回了我的数据,因此我必须更改返回答案的使用方式。感谢您的帮助。这让我找到了我的答案,wp\u remote\u post
以数组形式返回了我的数据,因此我必须更改返回答案的使用方式。感谢您的帮助。这让我找到了我的答案,wp\u remote\u post
以数组形式返回了我的数据,因此我必须更改返回答案的使用方式。谢谢你的帮助。