繁体   English   中英

对API的请求在Postman中有效,但在我尝试使用laravel / guzzle时无效

[英]Request to API works in Postman but not when I try with laravel/guzzle

我制作了一个API,现在尝试访问该API。 与邮递员一起,一切都完美无缺,而且运作良好:

在此处输入图片说明

但是当我用代码在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
        ]
]);

我有:

宾语

数据:调试:类:“ Symfony \\ Component \\ HttpKernel \\ Exception \\ UnauthorizedHttpException”文件:“ /home/user_name/public_html/vendor/dingo/api/src/Auth/Auth.php”行:113

怎么了 为什么在Postman中工作,但不能与Laravel / Guzzle库一起工作?

在Postman中,您似乎正在将令牌作为请求参数发送。 在您的代码中,您似乎正在使用form_params,它们是application / x-www-form-urlencoded。

试试这个: 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM