用于Bing的Bing搜索的Windows Azure身份验证

Gap*_*ton 2 php authentication header http azure

我正在尝试使用Windows Azure Marketplace API执行Bing搜索,我已下载了他们的指南和示例代码.该代码使用基本身份验证准备HTTPS请求,但是我不断收到以下错误:

Warning: file_get_contents(https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=%27washburn%27&Adult=%27Off%27&$top=50&$format=Atom): failed to open stream: Connection refused

php代码(来自微软的文档):

$context = stream_context_create(array(
    'http' => array(
    'proxy' => 'tcp://127.0.0.1:8888',
    'request_fulluri' => true,
    'header'  => "Authorization: Basic " . base64_encode($accountKey.":".$accountKey)
    )
));
Run Code Online (Sandbox Code Playgroud)

有谁知道导致错误的原因是什么?我已正确设置$accountKey并在浏览器中对其进行了测试.令我困惑的是127.0.0.1:8888,而且base64_encode($accountKey.":".$accountKey),为什么在使用浏览器$accountKey之前和之后需要:使用浏览器,你应该将用户名留空,只需将帐户密钥输入密码字段?

Gap*_*ton 8

我已经解决了这个问题,这就是我为未来的人们所做的事情:

我评论说它的行:

'proxy' => 'tcp://127.0.0.1:8888',
'request_fulluri' => true,
Run Code Online (Sandbox Code Playgroud)

并设置base64_encode("ignored:".$accountKey)代替

基于我在MSDN上读到的内容,用户名部分被认为被忽略了,所以它的价值无关紧要.我想也许钥匙的长度或特殊字符搞砸了所以我用ignored(或任何真正的)替换它.

这样做了,我可以解析返回的JSON数据.祝好运!