wp_safe_remote_post( string $url, array $args = array() ): array|WP_Error
Retrieve the raw response from a safe HTTP request using the POST method.
Contents
Description
This function is ideal when the HTTP request is being made to an arbitrary URL. The URL is validated to avoid redirection and request forgery attacks.
See also
- wp_remote_request() : For more information on the response array format.
- WP_Http::request(): For default arguments information.
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
Source
File: wp-includes/http.php
.
View all references
function wp_safe_remote_post( $url, $args = array() ) {
$args['reject_unsafe_urls'] = true;
$http = _wp_http_get_object();
return $http->post( $url, $args );
}
Changelog
Version | Description |
---|---|
3.6.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
See also https://developer.wordpress.org/reference/functions/wp_remote_post/