Bing搜索API Azure的市场验证在Java中 [英] Bing Search API Azure Marketplace Authentication in Java

查看:181
本文介绍了Bing搜索API Azure的市场验证在Java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何可以在Java身份验证使用新的必应搜索API从Azure的市场?迁移指南未提供有关Java的信息

How can I authenticate in Java to use the new bing search api from Azure Marketplace?The migration guide does not provide you with info about Java

推荐答案

您需要连接code你accountKey为Base64并使用Authorization头将它传递给每个请求。

You'll need to encode your accountKey to Base64 and pass it to each request using the Authorization header.

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);

...

这code是基于在迁移到必应搜索API发现PHP的例子在Windows Azure的市场文件。

This code is based on the the PHP example found in the Migrating to the Bing Search API in Windows Azure Marketplace document.

更新:修改了EN codeBase64调用,它应该是这样的:accountKey +:+ accountKey

Update: Modified the encodeBase64 call, it should be like this: accountKey + ":" + accountKey

这篇关于Bing搜索API Azure的市场验证在Java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆