0
認証されたHTTP GETリクエストを作成しようとしましたが、401 HTTPエラーが発生します。署名が正しいと確信しています。そのため、問題は18行目の複数のヘッダにあると思います。しかし、残念なことに正確な問題を見つけることはできません。PHP file_get_contentsにHTTPコード401が返されるUncomhorized
警告:file_get_contents(http://test.com/path):ストリームのオープンに失敗しました:HTTP要求に失敗しました。 HTTP/1.1のライン上の/home/host/path.phpで無断401 22
<?php
$apiKey = '1';
$apiSecret = '2';
$verb = 'GET';
$path = '/path';
$nonce = '1';
$data = '';
$signature = hash_hmac('sha256', $verb . $path . $nonce . $data, $apiSecret);
$url="http://test.com/path";
$opts = [
"http" => [
"method" => $verb,
"header" => "api-nonce: ".$nonce. "\r\n", "api-key: " .$apiKey. "\r\n", "api-signature: " . $signature
]
];
$context = stream_context_create($opts);
$json = file_get_contents($url, false, $context);
if($json){
$data = @json_decode($json, TRUE);
print_r($data);
}
?>
ありがとう!今は完璧に動作します。 – Remco