如何在不使用BingSearchContainer的情况下对bing search api
进行身份验证。
使用 bing搜索容器,我们可以执行以下操作:
var bing = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/")) { Credentials = new NetworkCredential(bingKey, bingKey) };
但这对我没有帮助,因为我需要传递一些其他代理来访问互联网。
任何人都可以帮我吗?
答案 0 :(得分: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();