Languages: English • 日本語 (Add your language)
Retrieve the raw response from the HTTP request using the GET method. Results include HTTP headers and content.
See wp_remote_post() for using the HTTP POST method
<?php $response = wp_remote_get( $url, $args ); ?>
<?php
global $wp_version;
$args = array(
'timeout' => 5,
'redirection' => 5,
'httpversion' => '1.0',
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url(),
'blocking' => true,
'headers' => array(),
'cookies' => array(),
'body' => null,
'compress' => false,
'decompress' => true,
'sslverify' => true,
'stream' => false,
'filename' => null
);
?>
See HTTP API for more information on the arguments array format.
Get a remote URL:
$response = wp_remote_get( 'http://www.example.com/index.html' );
if ( is_array( $response ) ) {
$header = $response['headers']; // array of http header lines
$body = $response['body']; // use the content
}
Get a remote URL with special arguments:
wp_remote_get( 'http://www.example.com/index.php?action=foo', array( 'timeout' => 120, 'httpversion' => '1.1' ) );
Use wp_remote_retrieve_body( $response ) to get the response body.
Use wp_remote_retrieve_response_code( $response ) to get the HTTP status code for the response.
Use related functions in wp-includes/http.php to get other parameters such as headers.
See WP_Http_Streams::request() method located in wp-includes/class-wp-http-streams.php for the format of the array returned by wp_remote_get().
Since: 2.7.0
wp_remote_get() is located in wp-includes/http.php
HTTP API: wp_remote_request(), wp_remote_get(), wp_remote_post(), wp_remote_head() wp_remote_retrieve_body(), wp_remote_retrieve_header(), wp_remote_retrieve_headers(), wp_remote_retrieve_response_code(), wp_remote_retrieve_response_message()