wp_remote_request
Retrieve the raw response from the HTTP request.
Description
The array structure is a little complex:
headers => array(…), response => array( code => int, message => string )
All of the headers in $res
[headers ] are with the name as the key and the value as the value. So to get the User-Agent, you would do the following.
The body is the raw response content and can be retrieved from $res
['body'].
This function is called first to make the request and there are other API functions to abstract out the above convoluted setup.
Request method defaults for helper functions: - Default GET for wp_remote_get(…)
- Default POST for wp_remote_post(…)
- Default HEAD for wp_remote_head(…)
Returns (WP_Error|array)
The response or WP_Error on failure.
Parameters (2)
- 0. $url (string)
- Site URL to retrieve.
- 1. $args — Optional. (array) =>
array()
- Request arguments. Default empty array.
Usage
if ( !function_exists( 'wp_remote_request' ) ) { require_once ABSPATH . WPINC . '/http.php'; } // Site URL to retrieve. $url = ''; // Optional. Request arguments. Default empty array. $args = array(); // NOTICE! Understand what this does before running. $result = wp_remote_request($url, $args);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/http.php
- function wp_remote_request($url, $args = array()) {
- $http = _wp_http_get_object();
- return $http->request( $url, $args );
- }