If you’re sending json, your code should look something like this:
$response = wp_remote_post($url, array(
'headers' => array('Content-Type' => 'application/json; charset=utf-8'),
'body' => $json,
'method' => 'POST'
));
if ( is_wp_error( $response ) ) {
die($response->get_error_message());
}
$body = json_decode(wp_remote_retrieve_body($response));
if ($body->error) {
die($body->error_msg);
}
If you’re getting json from somewhere else, then
$request = wp_remote_get($url);
if( is_wp_error( $request ) ) {
return false; // Bail early
}
$json = wp_remote_retrieve_body( $request );