2016-01-28 31 views
0

如何在不使用BingSearchContainer的情况下对bing search api进行身份验证。
c#中的Bing搜索API Azure市场身份验证#

随着bing搜索容器,我们可以做这样的事情:

var bing = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/")) { Credentials = new NetworkCredential(bingKey, bingKey) }; 

但是,这并不能帮助我,因为我需要通过一些其他的代理来访问互联网。

任何人都可以帮助我吗?

回答

0

一种方法是创建具有基本授权的WebRequest
像这样:

 //some demo uri 
    Uri uri = new Uri("https://api.datamarket.azure.com/Bing/Search/Composite?Sources=%27web%27&Query=%27xbox%27&$format=json"); 
    System.Net.WebRequest req = System.Net.WebRequest.Create(uri); 
    byte[] byteKey = System.Text.ASCIIEncoding.ASCII.GetBytes(bingKey + ":" + bingKey); 
    string stringKey = System.Convert.ToBase64String(byteKey); 
    req.Headers.Add("Authorization", "Basic " + stringKey); 
    req.Proxy = new System.Net.WebProxy("proxy_url", true); 
    req.Proxy.Credentials = new NetworkCredential("", "", ""); 
    System.Net.WebResponse resp = req.GetResponse();