[英]guzzle php post request response issue
I am able to make a post request with guzzle php using the following code 我可以使用以下代码使用guzzle php发出发布请求
$request = $this->request('POST', $this->url, array('form_params' => $params));
Everything works fine. 一切正常。 But when I call
但是当我打电话
$request->getBody()->getContents();
A string "root" is attached to the beginning of the content returned. 字符串“ root”附加到返回内容的开头。
I dont seems to understand why this is happening. 我似乎不明白为什么会这样。
Any assistance will be appreciated. 任何帮助将不胜感激。
An example of what I get when I var_dump is this 我在var_dump中得到的一个例子是
string(4) "root"
{"access_token":"kjVbpzmk3VAWTHn3jyeaM1nal1zkFIPZrI8khmKQ",
"token_type":"Bearer",
"expires_in":604800,
"user_id":3,
"user":{
"id":3,
"name":"Thomas Paul"
}
}
Meanwhile in postman I get this 同时在邮递员中我得到了
{
"access_token": "y9Jeovb3EERC4oE13yCS8WfFi3XK1eul4D4luwX3",
"token_type": "Bearer",
"expires_in": 604800,
"user_id": 3,
"user": {
"id": 3,
"name": "Thomas Paul"
}
}
This is a security measure as there is a known security vulnerability in some browsers. 这是一种安全措施,因为某些浏览器中存在一个已知的安全漏洞 。
Also the JSON API specs require this top level element . JSON API规范也需要此顶级元素 。
Guzzle is a really robust library. Guzzle是一个非常强大的库。 Maybe Postman isn't or maybe Postman removes the root element by itself... I don't know this.
也许邮递员不是,或者邮递员本身会删除根元素...我不知道这一点。
I solved the problem using a 我使用
substr($request->getBody()->getContents(), 17)
of the response and was able to remove the unwanted strings and decoded it to json 响应,并能够删除不需要的字符串并将其解码为json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.