我试图在Laravel中构建一个Guzzle请求以使用public / prvate密钥连接到API,并且我一直收到401 auth错误...
这是我的代码:
$client = new GuzzleHttp\Client(['base_uri' => 'https://api.myprivateurl.com/api/']);
$response = $client->get("accounts/$account", ['headers'=>['DefaultPublicKey'=>'PublicKey', 'DefaultPrivateKey'=>'Private Key']]);
echo $response->getBody();
以下是他们记录的要求:
私人const字符串BaseUri = @" https://api2.tigerpawsoftware.com&#34 ;;
私有const字符串DefaultAcceptHeader =" application / xml&#34 ;;
private const string DefaultPublicKey = [Public Key];
私有const字符串DefaultPrivateKey = [私钥];
我一直在互联网上搜索,我完全迷失了。 (我可以让Github API工作正常!!!)
答案 0 :(得分:0)
尝试在网址中发送身份验证凭据:
$response = $client->get("accounts/$account", [
'headers' => [
'Content-Type' => 'application/xml'
],
'query'=>[
'DefaultPublicKey' => 'PublicKey',
'DefaultPrivateKey' => 'Private Key'
]
]);