WordPress at a glance

wp_remote_request() WP 1.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()
  • See: WP_Http::request() For additional information on default arguments.

No Hooks.

Return

WP_Error/Array. The response or WP_Error on failure.

Usage

wp_remote_request( $url, $args );
$url(string) (required)
Site URL to retrieve.
$args(array)
Request arguments.
Default: empty array

Code of wp_remote_request: wp-includes/http.php VER 5.0.1

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

Related Functions

From tag: HTTP API (curl remote)

No comments
    Hello, !     Log In . Register