[英]Request to API works in Postman but not when I try with laravel/guzzle
I make an API and now I try to access to that API. 我制作了一个API,现在尝试访问该API。 WIth Postman everything is perfect and works fine:
与邮递员一起,一切都完美无缺,而且运作良好:
but when I try the same with guzzle/laravel with code: 但是当我用代码在guzzle / laravel上尝试相同时:
$res3 = $client3->post('https://app.EXAMPLE.com/api/update/'.$serial, [
'headers' => [
'Authorization' => 'Bearer '.$res2['token'],
'Content-Type' => 'application/json'
],
'form_params' => [
'token' => $res2['token'],
'bookingdate' => '07/07/2018 12:00 am',
'notes' => $SpecialRequests
]
]);
I got: 我有:
Object 宾语
data : debug : class : "Symfony\\Component\\HttpKernel\\Exception\\UnauthorizedHttpException" file : "/home/user_name/public_html/vendor/dingo/api/src/Auth/Auth.php" line : 113
数据:调试:类:“ Symfony \\ Component \\ HttpKernel \\ Exception \\ UnauthorizedHttpException”文件:“ /home/user_name/public_html/vendor/dingo/api/src/Auth/Auth.php”行:113
What is a problem? 怎么了 WHy works in Postman but won't work with Laravel/Guzzle library?
为什么在Postman中工作,但不能与Laravel / Guzzle库一起工作?
In Postman, it looks like you are sending the token as a request parameter. 在Postman中,您似乎正在将令牌作为请求参数发送。 In your code, it looks like you are using form_params, which are application/x-www-form-urlencoded.
在您的代码中,您似乎正在使用form_params,它们是application / x-www-form-urlencoded。
Try this: http://docs.guzzlephp.org/en/stable/quickstart.html#query-string-parameters 试试这个: http : //docs.guzzlephp.org/en/stable/quickstart.html#query-string-parameters
$res3 = $client3->post('https://app.EXAMPLE.com/api/update/'.$serial, [ 'headers' => [ 'Authorization' => 'Bearer '.$res2['token'], 'Content-Type' => 'application/json' ], 'query' => [ 'token' => $res2['token'], 'bookingdate' => '07/07/2018 12:00 am', 'notes' => $SpecialRequests ] ]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.