mirror of
https://ghproxy.net/https://github.com/wp-cli/handbook.git
synced 2026-07-26 12:37:22 +08:00
3.4 KiB
3.4 KiB
WP_CLI\Utils\http_request()
Make a HTTP request to a remote URL.
Usage
WP_CLI\Utils\http_request( $method, $url, $data = null, $headers = [], $options = [] )
$method (string) HTTP method (GET, POST, DELETE, etc.).
$url (string) URL to make the HTTP request to.
$data (array|null) Data to send either as a query string for GET/HEAD requests,
or in the body for POST requests.
$headers (array) Add specific headers to the request.
$options (array) {
Optional. An associative array of additional request options.
@type bool $halt_on_error Whether or not command execution should be halted on error. Default: true
@type bool|string $verify A boolean to use enable/disable SSL verification
or string absolute path to CA cert to use.
Defaults to detected CA cert bundled with the Requests library.
@type bool $insecure Whether to retry automatically without certificate validation.
@type int $max_retries Maximum number of retries of failed requests. Default 3.
}
@return (\Requests_Response|Response)
$url (string) URL to make the HTTP request to.
$data (array|null) Data to send either as a query string for GET/HEAD requests,
or in the body for POST requests.
$headers (array) Add specific headers to the request.
$options (array) {
Optional. An associative array of additional request options.
@type bool $halt_on_error Whether or not command execution should be halted on error. Default: true
@type bool|string $verify A boolean to use enable/disable SSL verification
or string absolute path to CA cert to use.
Defaults to detected CA cert bundled with the Requests library.
@type bool $insecure Whether to retry automatically without certificate validation.
@type int $max_retries Maximum number of retries of failed requests. Default 3.
}
@return (\Requests_Response|Response)
Notes
Wraps the Requests HTTP library to ensure every request includes a cert.
# `wp core download` verifies the hash for a downloaded WordPress archive
$md5_response = Utils\http_request( 'GET', $download_url . '.md5' );
if ( 20 != substr( $md5_response->status_code, 0, 2 ) ) {
WP_CLI::error( "Couldn't access md5 hash for release (HTTP code {$response->status_code})" );
}
Internal API documentation is generated from the WP-CLI codebase on every release. To suggest improvements, please submit a pull request.
Related
- WP_CLI\Utils\write_csv() - Write data as CSV to a given file.
- WP_CLI\Utils\get_named_sem_ver() - Compare two version strings to get the named semantic version.
- WP_CLI\Utils\parse_ssh_url() - Parse a SSH url for its host, port, and path.
- WP_CLI\Utils\basename() - Locale-independent version of basename()
- WP_CLI\Utils\isPiped() - Checks whether the output of the current script is a TTY or a pipe / redirect
- WP_CLI\Utils\proc_open_compat() - Windows compatible `proc_open()`. Works around bug in PHP, and also deals with *nix-like `ENV_VAR=blah cmd` environment variable prefixes.
- WP_CLI\Utils\esc_like() - First half of escaping for LIKE special characters % and _ before preparing for MySQL.