The*_*dis 5 authentication search azure bing-api odata
如何在Java中进行身份验证以使用Azure Marketplace中的新bing搜索API?迁移指南不向您提供有关Java的信息
您需要将accountKey编码为Base64,并使用Authorization标头将其传递给每个请求.
String bingUrl = "https://api.datamarket.azure.com/Bing/Search/................";
String accountKey = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
byte[] accountKeyBytes = Base64.encodeBase64((accountKey + ":" + accountKey).getBytes());
String accountKeyEnc = new String(accountKeyBytes);
URL url = new URL(bingUrl);
URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("Authorization", "Basic " + accountKeyEnc);
...
Run Code Online (Sandbox Code Playgroud)
此代码基于Windows Azure Marketplace文档中迁移到Bing Search API中的PHP示例.
更新:修改了encodeBase64调用,它应该是这样的:accountKey +":"+ accountKey
| 归档时间: |
|
| 查看次数: |
4558 次 |
| 最近记录: |