WordPress.org

Codex

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

Function Reference/wp remote retrieve body

This page is marked as incomplete. You can help Codex by expanding it.

Description

Retrieve only the body from the raw response.

Usage

<?php $body wp_remote_retrieve_body($response); ?>

Parameters

$response
(array) (required) HTTP response.
Default: None

Return Values

(string) 
The body of the response. Empty string if no body or incorrect parameter given.

Examples

Retrieving data from a JSON API:

$url      = 'http://example.org/api';
$response = wp_remote_get( $url );

/* Will result in $api_response being an array of data,
parsed from the JSON response of the API listed above */
$api_response = json_decode( wp_remote_retrieve_body( $response ), true );

Notes

Change Log

Since: 2.7.0

Source File

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

Related