本文介绍了如果我不需要回应,如何使用Wordpress wp_remote_post?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 wp_remote_post 将表单数据(联系表单7 )发送到外部API(CRM)。 API很重(检查电子邮件,确认信等),所以我不希望PHP在等待响应时阻止任何进程(我根本不需要响应,只需发送)。

Using wp_remote_post to send form data (Contact Form 7) to external API (CRM). API is heavy (checking emails, confirmation letters, etc), so I don't want PHP to block any processes, while waiting for a response (I don't need response at all, just send).

仍然,即使'blocking'=> false 的确如此-如果我在外部API上激活确认电子邮件,则Wordpress用户需要等待几秒钟才能处理表单。

Still, even with 'blocking' => false it does — if I activate confirmation emails on external API, Wordpress users need to wait several seconds before form is processed.

我是什么做错了吗? :)代码:

What am I doing wrong? :) Code:

// POST-request to API
wp_remote_post('http://crm.site.com/get_record', array(
    'timeout' => 5,
    'redirection' => 5,
    'httpversion' => '1.0',
    'blocking' => false,
    'headers' => array() ,
    'body' => $send_data,
    'cookies' => array()
));


推荐答案

我认为这里缺少方法,请添加方法并尝试

I think method is missing here, add method and try

   $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>';
}

这篇关于如果我不需要回应,如何使用Wordpress wp_remote_post?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 08:47