WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp remote get

Contents

Description

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

Usage

<?php $response wp_remote_get$url$args ?>

Default Usage

<?php $args = array(
    'timeout'     => 5,
    'redirection' => 5,
    'httpversion' => '1.0',
    'user-agent'  => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ),
    'blocking'    => true,
    'headers'     => array(),
    'cookies'     => array(),
    'body'        => null,
    'compress'    => false,
    'decompress'  => true,
    'sslverify'   => true,
    'stream'      => false,
    'filename'    => null
); ?>

Parameters

$url
(string) (required) Site URL to retrieve.
Default: None
$args
(array) (optional) Override the defaults.
Default: array()

See HTTP API for more information on the arguments array format.

Return Values

(WP_Error|array) 
The response or WP_Error on failure. See wp_remote_post() for a full example of response array format.

Examples

Get a remote URL:

wp_remote_get( 'http://www.example.com/index.html' );

Get a remote URL with special arguments:

wp_remote_get( 'http://www.example.com/index.php?action=foo', array( 'timeout' => 120, 'httpversion' => '1.1' ) );

Notes

Change Log

Since: 2.7.0

Source File

wp_remote_get() is located in wp-includes/http.php

Related

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()