Php 如果我没有';你不需要回复吗?
使用Php 如果我没有';你不需要回复吗?,php,wordpress,contact-form-7,Php,Wordpress,Contact Form 7,使用wp\u remote\u post将表单数据(联系表单7)发送到外部API(CRM)。API很重(检查电子邮件、确认信等),所以我不希望PHP在等待响应时阻止任何进程(我根本不需要响应,只需发送) 尽管如此,即使使用'blocking'=>false它也会这样做-如果我在外部API上激活确认电子邮件,Wordpress用户需要等待几秒钟才能处理表单 我做错了什么?:)代码: 我认为这里缺少方法,请添加方法并重试 $response = wp_remote_post('http://c
wp\u remote\u post
将表单数据(联系表单7
)发送到外部API(CRM)。API很重(检查电子邮件、确认信等),所以我不希望PHP在等待响应时阻止任何进程(我根本不需要响应,只需发送)
尽管如此,即使使用'blocking'=>false它也会这样做-如果我在外部API上激活确认电子邮件,Wordpress用户需要等待几秒钟才能处理表单
我做错了什么?:)代码:
我认为这里缺少方法,请添加方法并重试
$response = wp_remote_post('http://crm.site.com/get_record', array(
'method' => 'POST',
'timeout' => 5,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => false,
'headers' => array() ,
'body' => $send_data,
'cookies' => array()
));
并检查响应:
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}
if(是wp\u错误($response)){
$error_message=$response->get_error_message();
echo“出错:$error_message”;
}否则{
回应"回应";;
打印(回复);
回声';
}
太棒了!这解决了问题为什么当方法本身发出post请求时需要指定方法,我的意思是默认值已经是post了,这不是多余的吗?是的,post是可选的,您也可以忽略它@但是我的意思是,为什么它解决了这个问题?伊姆河confused@svelandiag它没有,一定是其他原因,可能是正确地读取了错误消息。请求完全相同,因为这只是一个助手函数,它只向标准请求添加'method'=>'POST'
。
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}