wp_remote_request

The timeline below displays how wordpress function wp_remote_request has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Performs an HTTP request and returns its response.
 *
 * There are other API functions available which abstract away the HTTP method:
 *
 *  - Default 'GET'  for wp_remote_get()
 *  - Default 'POST' for wp_remote_post()
 *  - Default 'HEAD' for wp_remote_head()
 *
 * @since 2.7.0
 *
 * @see WP_Http::request() For information on default arguments.
 *
 * @param string $url  URL to retrieve.
 * @param array  $args Optional. Request arguments. Default empty array.
 *                     See WP_Http::request() for information on accepted arguments.
 * @return array|WP_Error {
 *     The response array or a WP_Error on failure.
 *
 *     @type string[]                       $headers       Array of response headers keyed by their name.
 *     @type string                         $body          Response body.
 *     @type array                          $response      {
 *         Data about the HTTP response.
 *
 *         @type int|false    $code    HTTP response code.
 *         @type string|false $message HTTP response message.
 *     }
 *     @type WP_HTTP_Cookie[]               $cookies       Array of response cookies.
 *     @type WP_HTTP_Requests_Response|null $http_response Raw HTTP response object.
 * }
 */
function wp_remote_request($url, $args = array())
{
    $http = _wp_http_get_object();
    return $http->request($url, $args);
}

WordPress Version: 5.4

/**
 * Performs an HTTP request and returns its response.
 *
 * There are other API functions available which abstract away the HTTP method:
 *
 *  - Default 'GET'  for wp_remote_get()
 *  - Default 'POST' for wp_remote_post()
 *  - Default 'HEAD' for wp_remote_head()
 *
 * @since 2.7.0
 *
 * @see WP_Http::request() For information on default arguments.
 *
 * @param string $url  URL to retrieve.
 * @param array  $args Optional. Request arguments. Default empty array.
 * @return array|WP_Error {
 *     The response array or a WP_Error on failure.
 *
 *     @type string[]                       $headers       Array of response headers keyed by their name.
 *     @type string                         $body          Response body.
 *     @type array                          $response      {
 *         Data about the HTTP response.
 *
 *         @type int|false    $code    HTTP response code.
 *         @type string|false $message HTTP response message.
 *     }
 *     @type WP_HTTP_Cookie[]               $cookies       Array of response cookies.
 *     @type WP_HTTP_Requests_Response|null $http_response Raw HTTP response object.
 * }
 */
function wp_remote_request($url, $args = array())
{
    $http = _wp_http_get_object();
    return $http->request($url, $args);
}

WordPress Version: 5.3

/**
 * Performs an HTTP request and returns its response.
 *
 * There are other API functions available which abstract away the HTTP method:
 *
 *  - Default 'GET'  for wp_remote_get()
 *  - Default 'POST' for wp_remote_post()
 *  - Default 'HEAD' for wp_remote_head()
 *
 * @since 2.7.0
 *
 * @see WP_Http::request() For information on default arguments.
 *
 * @param string $url  URL to retrieve.
 * @param array  $args Optional. Request arguments. Default empty array.
 * @return WP_Error|array {
 *     The response array or a WP_Error on failure.
 *
 *     @type string[]                       $headers       Array of response headers keyed by their name.
 *     @type string                         $body          Response body.
 *     @type array                          $response      {
 *         Data about the HTTP response.
 *
 *         @type int|false    $code    HTTP response code.
 *         @type string|false $message HTTP response message.
 *     }
 *     @type WP_HTTP_Cookie[]               $cookies       Array of response cookies.
 *     @type WP_HTTP_Requests_Response|null $http_response Raw HTTP response object.
 * }
 */
function wp_remote_request($url, $args = array())
{
    $http = _wp_http_get_object();
    return $http->request($url, $args);
}

WordPress Version: 4.3

/**
 * Retrieve the raw response from the HTTP request.
 *
 * The array structure is a little complex:
 *
 *     $res = array(
 *         '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.
 *
 *     $user_agent = $res['headers']['user-agent'];
 *
 * 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()
 *
 * @since 2.7.0
 *
 * @see WP_Http::request() For additional information on default arguments.
 *
 * @param string $url  Site URL to retrieve.
 * @param array  $args Optional. Request arguments. Default empty array.
 * @return WP_Error|array The response or WP_Error on failure.
 */
function wp_remote_request($url, $args = array())
{
    $http = _wp_http_get_object();
    return $http->request($url, $args);
}

WordPress Version: 4.0

/**
 * Retrieve the raw response from the HTTP request.
 *
 * The array structure is a little complex:
 *
 *     $res = array(
 *         '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.
 *
 *     $user_agent = $res['headers']['user-agent'];
 *
 * 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()
 *
 * @since 2.7.0
 *
 * @see WP_Http::request() For additional information on default arguments.
 *
 * @param string $url  Site URL to retrieve.
 * @param array  $args Optional. Request arguments. Default empty array.
 * @return WP_Error|array The response or WP_Error on failure.
 */
function wp_remote_request($url, $args = array())
{
    $objFetchSite = _wp_http_get_object();
    return $objFetchSite->request($url, $args);
}

WordPress Version: 3.7

/**
 * Retrieve the raw response from the HTTP request.
 *
 * The array structure is a little complex.
 *
 * <code>
 * $res = array( 'headers' => array(), 'response' => array('code' => int, 'message' => string) );
 * </code>
 *
 * 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.
 *
 * <code>
 * $user_agent = $res['headers']['user-agent'];
 * </code>
 *
 * 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.
 *
 * List of default arguments:
 * 'method'      => 'GET'
 *  - Default 'GET'  for wp_remote_get()
 *  - Default 'POST' for wp_remote_post()
 *  - Default 'HEAD' for wp_remote_head()
 * 'timeout'     => 5
 * 'redirection' => 5
 * 'httpversion' => '1.0'
 * 'user-agent'  => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
 * 'blocking'    => true
 * 'headers'     => array()
 * 'cookies'     => array()
 * 'body'        => null
 * 'compress'    => false,
 * 'decompress'  => true,
 * 'sslverify'   => true,
 * 'stream'      => false,
 * 'filename'    => null
 *
 * @since 2.7.0
 *
 * @param string $url Site URL to retrieve.
 * @param array $args Optional. Override the defaults.
 * @return WP_Error|array The response or WP_Error on failure.
 */
function wp_remote_request($url, $args = array())
{
    $objFetchSite = _wp_http_get_object();
    return $objFetchSite->request($url, $args);
}