我正在尝试围绕我公司正在开发的api编写一个包装器.它很安静,使用Postman我可以发送一个帖子请求到一个端点,比如http://subdomain.dev.myapi.com/api/v1/auth/使用用户名和密码作为POST数据,我会收到一个令牌.一切都按预期工作.现在,当我尝试从PHP执行相同操作时,我会返回一个GuzzleHttp\Psr7\Response对象,但似乎无法在其中的任何位置找到令牌,就像我对Postman请求所做的那样.
相关代码如下:
$client = new Client(['base_uri' => 'http://companysub.dev.myapi.com/']);
$response = $client->post('api/v1/auth/', [
'form_params' => [
'username' => $user,
'password' => $password
]
]);
var_dump($response); //or $resonse->getBody(), etc...
Run Code Online (Sandbox Code Playgroud)
上面代码的输出看起来像(警告,传入文本墙):
object(guzzlehttp\psr7\response)#36 (6) {
["reasonphrase":"guzzlehttp\psr7\response":private]=>
string(2) "ok"
["statuscode":"guzzlehttp\psr7\response":private]=>
int(200)
["headers":"guzzlehttp\psr7\response":private]=>
array(9) {
["connection"]=>
array(1) {
[0]=>
string(10) "keep-alive"
}
["server"]=>
array(1) {
[0]=>
string(15) "gunicorn/19.3.0"
}
["date"]=>
array(1) {
[0]=>
string(29) "sat, 30 may 2015 17:22:41 gmt"
}
["transfer-encoding"]=>
array(1) {
[0]=>
string(7) "chunked"
}
["content-type"]=>
array(1) {
[0]=> …Run Code Online (Sandbox Code Playgroud)