laravel 和 guzzle auth
laravel and guzzle auth
嗨,我想使用一项服务,我使用 laravel 5.x 和这段代码,我可以发送请求,我使用正确的 api-key 但我总是获得403 禁止....
public function searchP(Request $request) {
$targa = request('targa');
$client = new \GuzzleHttp\Client();
$url = 'https://xxx.it/api/xxx/xxx-number/'.$targa.'/xxx-xxxx';
$api_key ='xxxxxcheepohxxxx';
try {
$response = $client->request(
'GET',
$url,
['auth' => [null, $api_key]]);
} catch (RequestException $e) {
var_dump($e->getResponse()->getBody()->getContent());
}
// Get JSON
$result = $response->json();
}
为什么?看不懂
在邮递员中,我在授权标签中写了这个
- 键:x-api键
- 值:xxxxxcheepohxxxx
- 添加到页眉
并且有效。
我也试过这个
.... try {
$response = $client->request('GET',$url,[
'headers' => [
'x-apikey', $api_key
]
]);
} catch .....
但不起作用
谢谢
应该是这个,打错了
.... try {
$response = $client->request('GET',$url,[
'headers' => [
'x-apikey'=> $api_key
]
]);
} catch .....
嗨,我想使用一项服务,我使用 laravel 5.x 和这段代码,我可以发送请求,我使用正确的 api-key 但我总是获得403 禁止....
public function searchP(Request $request) {
$targa = request('targa');
$client = new \GuzzleHttp\Client();
$url = 'https://xxx.it/api/xxx/xxx-number/'.$targa.'/xxx-xxxx';
$api_key ='xxxxxcheepohxxxx';
try {
$response = $client->request(
'GET',
$url,
['auth' => [null, $api_key]]);
} catch (RequestException $e) {
var_dump($e->getResponse()->getBody()->getContent());
}
// Get JSON
$result = $response->json();
}
为什么?看不懂
在邮递员中,我在授权标签中写了这个
- 键:x-api键
- 值:xxxxxcheepohxxxx
- 添加到页眉
并且有效。 我也试过这个
.... try {
$response = $client->request('GET',$url,[
'headers' => [
'x-apikey', $api_key
]
]);
} catch .....
但不起作用 谢谢
应该是这个,打错了
.... try {
$response = $client->request('GET',$url,[
'headers' => [
'x-apikey'=> $api_key
]
]);
} catch .....