Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
wp_remote_retrieve_body() - 仅从原始响应中检索body - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / wp_remote_retrieve_body()

wp_remote_retrieve_body( array|WP_Error $response )

仅从原始响应中检索body


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 4 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "af4e913ce2975e7e84605084283fd620" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "006cf7a66a945a4c149a101c5a5d49e1" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "034c4aafb381bf888f2199e32a8c35a5" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

body

remote 远程

retrieve


参数

$response

(array|WP_Error)(必填) HTTP响应。


返回

(string) 响应的body。如果未提供body或参数不正确,则为空字符串。



源码

查看源码 官方文档


更新日志

版本描述
2.7.0开始引入

使用示例

  • 示例1

    实例

    从JSON API检索数据:

    $url      = 'http://example.org/api';
    $response = wp_remote_get( esc_url_raw( $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 );
    
  • 示例2

    更好的性能?

    跳过额外的函数调用,从wp_remote_get()获取主体(或返回数组的任何其他部分)。这就是wp_remote_retrieve_body()正在做的事情。

    $url  = 'http://ecotechie.io/';
    $body = wp_remote_get( esc_url_raw( $url ) )['body'];