繁体   English   中英

PHP的其余卷曲身份验证标头项丢失

[英]php rest curl authentication header items missing

我正在尝试通过curl发送带有包含授权密钥和api密钥的标头的rest请求。

因此,我建立以下curl调用:

$api_key = 'abc';
$token = 'xyz';


$authorization = 'Authorization: Bearer ' . $token;
$api = 'Api_key: ' . $api_key;

curl_setopt($curl, CURLOPT_HTTPHEADER, array($authorization, $api));

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLINFO_HEADER_OUT, true); // Detail information for debugging
curl_setopt($curl,CURLOPT_VERBOSE,true);
$curl_response = curl_exec($curl);

在服务器端调试标头将显示标头集合,其中包括:

expect (array)
accept (array)
host (array)
authorization (array)

仔细查看授权数组可发现只有一项。 这是来自客户端的授权密钥的值。 标头/授权数组中缺少第二个值api_key。

客户端的Request_header显示,Api_key可用:

Host: localhost
Authorization: Basic RG9yaXMgS3JhenM6S3JhdXMxMDAw
Accept: */*
Api_key: abc
Content-Length: 458
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------224938f738738f42

为什么服务器无法接收基于数组的完整http标头身份验证信息。 开发环境是apache,php 7,yii,phpstorm。

我已经通过将API密钥作为“ x-api-key”放在HTTP标头中解决了该问题。

看起来像下面的代码:

$api_key = 'abc';
$token = 'xyz';

$authorization = 'Authorization: Bearer ' . $token;
$api = 'x-api-key: ' . $api_key;
curl_setopt($curl, CURLOPT_HTTPHEADER, array($authorization, $api));

暂无
暂无

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

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