Windows Azure的身份验证Bing搜索在PHP

问题描述:

我试图通过使用Windows Azure API市场执行一个Bing搜索,我已经下载了他们的向导和样品code。在code prepares基本身份验证的HTTPS请求,但是我经常收到以下错误:

I am trying to perform a Bing Search by using the Windows Azure Marketplace API, I have downloaded their guide and sample code. The code prepares a HTTPS request with basic authentication, however I am constantly getting the following error:

警告: file_get_contents(https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=%27washburn%27&Adult=%27Off%27&$top=50&$format=Atom):未能打开流:连接被拒绝

PHP的code(从微软的文档):

The php code (from Microsoft's document):

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

有谁知道是什么原因造成的错误吗?我已正确设置 $ accountKey ,我在浏览器中进行了测试。令我百思不解的一点是 127.0.0.1:8888 base64_en code($ accountKey。:$ accountKey),你怎么会需要 $ accountKey 之前和之后的在使用浏览器时,你应该要离开的用户名空白,只输入账号密码到密码字段?

Does anyone know what is causing the error please? I have correctly set the $accountKey and I tested it in a browser. What puzzles me a little is 127.0.0.1:8888 and also base64_encode($accountKey.":".$accountKey) , how come you need the $accountKey both before and after the : while when using a browser you are supposed to leave the username blank and just input the account key into the password field?

我已经解决了它,这是我已经找到了,将被做同样的事情将来人:

I have solved it and here is what I have found for future people that would be doing the same thing:

我注释掉,它说行:

'proxy' => 'tcp://127.0.0.1:8888',
'request_fulluri' => true,

和还设置 base64_en code(忽略。$ accountKey)而不是

这是我在MSDN上阅读基地,用户名部分被说成是的忽略,所以它不应该的问题是什么珍惜它是。我想也许是长度还是关键中的特殊字符搞砸的事情,所以我用替换它忽略(或任何真的)。

Base on what I read on MSDN, the username part is said to be ignored, so it shouldn't matter what value it is. I was thinking perhaps the length or the special characters in the key screwed things up so I replaces it with ignored (or anything really).

这奏效了,我可以分析返回的JSON数据。祝你好运!

That did the trick and I can parse the returned JSON data. Good luck!