java windows 身份验证_Java中的Windows Azure身份验证

在尝试使用Java进行Web搜索时,遇到使用Windows Azure Marketplace的身份验证问题,即便使用正确的帐户密钥仍收到HTTP 401错误。代码示例显示了设置Authorization请求头的过程,但授权失败。寻求解决方案。
摘要由CSDN通过智能技术生成

尽管我检查了以前在java中用于web搜索的azure认证的答案,但即使帐户密钥与我在Windows Azure Marketplace中的配置文件中的密钥完全相同,我仍然得到了HTTP错误代码:401。我尝试生成一个新的,但也没有工作。

所以任何帮助将非常感激。

这里是java代码(类似于其他人使用它):

String bingUrl = "https://api.datamarket.azure.com/Bing/Search/Web?Query='multiple'&$top=4&$skip=1&$format=json";

String accountKey = "key";

byte[] encoding = Base64.encodeBase64((accountKey + ":" + accountKey).getBytes());

String accountKeyEnc = new String(encoding);

URL url = new URL(bingUrl);

URLConnection urlConnection = url.openConnection();

urlConnection.setRequestProperty("Authorization", String.format("Basic ", accountKeyEnc));

BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

String inputLine;

StringBuffer sb = new StringBuffer();

while ((inputLine = in.readLine()) != null)

System.out.println(inputLine);

sb.append(inputLine);

in.close();

System.out.println( sb.toString());我得到的错误代码是:

java.io.IOException: Server returned HTTP response code: 401 for URL:

https://api.datamarket.azure.com/Bing/Search/Web?Query='multiple'&$top=4&$skip=1&$format=json

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown

Source) at

sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown

Source) at queryengines.WebSample.DisplayResults(WebSample.java:37)

at queryengines.WebSample.main(WebSample.java:19)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值