问题
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).
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()
));
回答1:
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()
));
And check response:
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>';
}
来源:https://stackoverflow.com/questions/52041684/how-to-use-wordpress-wp-remote-post-if-i-dont-need-to-get-a-response