Codex tools: Log in
Languages: English • (Add your language)
Contents |
Retrieves the body of an already retrieved HTTP request.
See Function_API/wp_remote_get for an example of the HTTP GET method.
<?php wp_remote_retrieve_body( $response ); ?>
Returns a string. If there was an error returned by the existing HTTP request or a problem with the data then a blank string will be returned.
Here is the content of the retrieved URL!
$the_body = wp_remote_retrieve_body( wp_remote_get('http://example.com') );
In the example above, $the_body will contain the actual page content returned by the server.
Below is the actual function code in WordPress. As you can see it simply checks that there was no error with the HTTP response and that the body is set. If so then it returns $response['body'].
function wp_remote_retrieve_body(&$response) {
if ( is_wp_error($response) || ! isset($response['body']) )
return '';
return $response['body'];
}
wp_remote_retrieve_body() is located in wp-includes/http.php.