简体   繁体   English

枪口错误500

[英]Guzzle error 500

so i have a CURL request that looks like this (and it works): 所以我有一个CURL请求,看起来像这样(并且有效):

curl -X GET -H "Authorization: Token 1234567890" http://api.website.com

tried translating it into Laravel Guzzle into something like this: 尝试将其翻译成Laravel Guzzle,如下所示:

$client = new \GuzzleHttp\Client(['base_uri' => 'http://api.website.com']);
$headers = ['Authorization' => 'Token 1234567890'];
$response = $client->get($query_string, $headers);
return $response;

but i'm getting a 500 error. 但我遇到500错误。 i think there's something wrong in how i implemented the headers. 我认为我实现标头的方式有问题。 sorry, very new in laravel and guzzle. 抱歉,laravel和guzzle中的新功能。

thanks! 谢谢!

get() takes options (which can contain headers) as a second parameter, not headers ( docs ). get()options (可以包含标头)作为第二个参数,而不是标头( docs )。

This should work: 这应该工作:

$client = new \GuzzleHttp\Client(['base_uri' => 'http://api.website.com']);
$headers = ['Authorization' => 'Token 1234567890'];
$response = $client->get(
    $query_string, [
        "headers" => $headers
        // you can add more options here
    ]
);
return $response;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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