我已经进行了 API 调用wp_remote_post并尝试使用 检索正文wp_remote_retrieve_body。但响应仅显示标头,而正文受到保护。
下面的代码,我用来进行 API 调用。
$args = array(
'LocationId' => $loc_id,
'AppId' => $app_id
);
$response = wp_remote_post( 'https://www.apiurl.com?APIKEY='."$api_key".'', $args );
$responceData = json_decode(wp_remote_retrieve_body( $response ), TRUE );
print_r($response);
Run Code Online (Sandbox Code Playgroud)
打印的响应(只是开始的数据)是:
数组 ( [headers] => Requests_Utility_CaseInsensitiveDictionary 对象 ( [data:protected]
我正在本地主机中开发 WordPress 插件。如何解决这个错误。
完整回应:
Array ( [headers] => Requests_Utility_CaseInsensitiveDictionary Object ( [data:protected] => Array ( [cache-control] => no-cache, no-store [pragma] => no-cache [content-type] => application/json; charset=utf-8 [expires] => -1 [server] => Microsoft-IIS/10.0 [access-control-allow-origin] => * [x-aspnet-version] …Run Code Online (Sandbox Code Playgroud)