Regarding to this post I started to create an AJAX handler with the default WordPress AJAX API. I want to call a non-blocking call to another AJAX handler, in the same WordPress site.
Order of processes:
- jQuery.ajax() to the wp-admin/admin-ajax?action=x_prepare
- wp_ajax_x_prepare() uses the wp_remote_get() function
$response = wp_remote_get(admin_url("admin-ajax.php?action=x_start"), array( "blocking" => false ));
- wp_ajax_x_start() is doing any not-relevant code for this question...
Then i get the following error from the wp_remote_get() function.
Array ( [headers] => Array ( ) [body] => [response] => Array ( [code] => [message] => ) [cookies] => Array ( ) [http_response] => ) 0
cURL is activated.
EDIT
Just found this post: Passing current cookies in wp_remote_get to get Draft Post Preview
When I try the same code:
$preview_link = set_url_scheme( get_permalink( 7250 ) );
$preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ) );
var_dump($preview_link);
$cookies = array();
foreach ( $_COOKIE as $name => $value ) {
$cookies[] = new WP_Http_Cookie( array( 'name' => $name, 'value' => $value ) );
}
$request = wp_remote_get( $preview_link, array( 'cookies' => $cookies ) );
$body = wp_remote_retrieve_body( $request );
... I get this error Missing header/body separator:
WP_Error#835 (2) { public $errors => array(1) { 'http_request_failed' => array(1) { [0] => string(29) "Missing header/body separator" } } public $error_data => array(0) { } } 0