我尝试进行经过身份验证的HTTP GET请求,但收到401 HTTP错误。 我确信签名是正确的。 因此,我认为问题出在第18行的多个标题中。但遗憾的是我无法找到确切的问题。 p>
警告:file_get_contents( http://test.com/path ):无法打开流:HTTP请求失败! 第22行/home/host/path.php中的HTTP / 1.1 401未授权 p> blockquote>
<?php $ apiKey ='1'; $ apiSecret ='2'; $ verb ='GET'; $ path ='/ path'; $ nonce ='1'; $ data =''; \ n $ signature = hash_hmac('sha256',$ verb。$ path。$ nonce。$ data,$ apiSecret); $ url =“http://test.com/path”; $ opts = [ “http”=> [ “method”=> $ verb, “header”=> “api-nonce:”。$ nonce。 “ ”,“api-key:”。$ apiKey。 “ ”,“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); } ?> code> pre> div>