【问题标题】:Bing Search API Azure Marketplace Authentication in c#C# 中的必应搜索 API Azure 市场身份验证
【发布时间】:2016-01-28 15:24:47
【问题描述】:

如何在不使用 BingSearchContainer 的情况下向bing search api 进行身份验证。

使用 bing 搜索容器,我们可以这样做:

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

但这对我没有帮助,因为我需要通过其他代理才能访问互联网。

谁能帮我解决这个问题?

【问题讨论】:

    标签: c# bing-api


    【解决方案1】:

    一种方法是创建具有基本授权的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();
    

    【讨论】:

      猜你喜欢
      • 2012-06-23
      • 1970-01-01
      • 2016-07-22
      • 2012-08-02
      • 2016-12-21
      • 2017-02-04
      • 2013-06-28
      • 1970-01-01
      • 2016-07-26
      相关资源
      最近更新 更多