I'm making a plugin that compares data from external API with meta items in WordPress backoffice.
I tried using wp_remote_get
method to query my API but it doesn't return anything, nobody, nothing. When accessed directly with the same URL in browser the API generates JSON array without problems.
What am I doing wrong?
This is (partially omitted code in the plugin)
..........
$chopped = explode("@", $meta['Email'][0]);
$url = 'http://example.com/api/users/'.$chopped[0].'/'.$chopped[1];
global $wp_version;
$args = array(
'timeout' => 5,
'redirection' => 5,
'httpversion' => '1.0',
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url(),
'blocking' => true,
'headers' => array(),
'cookies' => array(),
);
$response = wp_remote_get( $url, $args );
$body = wp_remote_retrieve_body( $response );
$http_code = wp_remote_retrieve_response_code( $response );
echo '<pre> Test dump: '.print_r($http_code,1).'</pre>';
edit 1: For those who might think it has to do with csrf protection or similiar, I can query the api from https://www.hurl.it/ without any problems too. Could the error be because I'm calling it inside a hook?
edit 2: The response code I'm getting
WP_Error Object
(
[errors] => Array
(
[http_request_failed] => Array
(
[0] => Connection timed out after 5003 milliseconds
)
)
[error_data] => Array
(
)
)