如何在GuzzleHttp中仅返回正文内容?

问题描述 投票:0回答:1

返回的JSON数据带有我不需要的标题内容,是否有过滤返回数据的方法?

这是我的PHP代码:

public function AreaGet($info){
    $res = $this->guzzClient->request('GET','v2/Address/Areas/Search',[
        'headers'=>['Authorization'=>'Bearer '.$this->keys()->access_token],
        'query'=>['countryCode'=>'ZAF','searchFor'=>$info->searchCity]
    ]);

    return json_decode($res->getBody()->getContents());
}

这就是我得到的回应:JSON RESPONSE

php http curl guzzle guzzlehttp
1个回答
0
投票

感谢大家的贡献!

我已经找到了问题,我应该在我的授权脚本中将'debug'设置为false

$request = $this->guzzClient->request('POST', 'Login', ['debug' => false,'form_params'=> $data]);

否则响应将附加到正文中的http和服务器信息

© www.soinside.com 2019 - 2024. All rights reserved.