wp_remote_request( string $url, array $args = array() ): array|WP_Error
Performs an HTTP request and returns its response.
Contents
Description
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()
See also
- WP_Http::request(): For information on default arguments.
Parameters
-
$url
string Required -
URL to retrieve.
-
$args
array Optional -
Request arguments.
See WP_Http::request() for information on accepted arguments.More Arguments from WP_Http::request( ... $args )
Array or string of HTTP request arguments.
method
stringRequest method. Accepts'GET'
,'POST'
,'HEAD'
,'PUT'
,'DELETE'
,'TRACE'
,'OPTIONS'
, or'PATCH'
.
Some transports technically allow others, but should not be assumed. Default'GET'
.timeout
floatHow long the connection should stay open in seconds. Default 5.redirection
intNumber of allowed redirects. Not supported by all transports.
Default 5.httpversion
stringVersion of the HTTP protocol to use. Accepts'1.0'
and'1.1'
.
Default'1.0'
.user-agent
stringUser-agent value sent.
Default'WordPress/'
. get_bloginfo('version'
) . '; ' . get_bloginfo('url'
).reject_unsafe_urls
boolblocking
boolWhether the calling code requires the result of the request.
If set to false, the request will be sent to the remote server, and processing returned to the calling code immediately, the caller will know if the request succeeded or failed, but will not receive any response from the remote server. Default true.headers
string|arrayArray or string of headers to send with the request.
cookies
arrayList of cookies to send with the request.body
string|arrayBody to send with the request. Default null.compress
boolWhether to compress the $body when sending the request.
Default false.decompress
boolWhether to decompress a compressed response. If set to false and compressed content is returned in the response anyway, it will need to be separately decompressed. Default true.sslverify
boolWhether to verify SSL for the request. Default true.sslcertificates
stringAbsolute path to an SSL certificate .crt file.
Default ABSPATH . WPINC .'/certificates/ca-bundle.crt'
.stream
boolWhether to stream to a file. If set to true and no filename was given, it will be dropped it in the WP temp dir and its name will be set using the basename of the URL. Default false.filename
stringFilename of the file to write to when streaming. $stream must be set to true. Default null.limit_response_size
intSize in bytes to limit the response to. Default null.
Default:
array()
Return
array|WP_Error The response array or a WP_Error on failure.
headers
string[]Array of response headers keyed by their name.body
stringResponse body.response
arrayData about the HTTP response.code
int|falseHTTP response code.message
string|falseHTTP response message.
cookies
WP_HTTP_Cookie[]Array of response cookies.http_response
WP_HTTP_Requests_Response|nullRaw HTTP response object.
Source
File:
wp-includes/http.php
. View all referencesfunction wp_remote_request( $url, $args = array() ) { $http = _wp_http_get_object(); return $http->request( $url, $args ); }
Changelog
Changelog Version Description 2.7.0 Introduced.
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Send a Delete request with wp_remote_post
You can insert the DELETE method inside
wp_remote_request()
like this:Sample ConvertKit API call function using wp_remote_request()
What about calling this function? Well here’s another function which updates a contact’s email address/name