wp_remote_request( string $url, array $args = array() )

Retrieve the raw response from the HTTP request.

Description Description

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:

Parameters Parameters


(string) (Required) Site URL to retrieve.


(array) (Optional) Request arguments.

Default value: array()

Top ↑

Return Return

(WP_Error|array) The response or WP_Error on failure.

Top ↑

Source Source

File: wp-includes/http.php

function wp_remote_request($url, $args = array()) {
	$http = _wp_http_get_object();
	return $http->request( $url, $args );

Top ↑

Changelog Changelog

Version Description
2.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.