Java中的窗口天蓝色身份验证...

String bingUrl = "https://api.datamarket.azure.com/Bing/Search/Web?Query='multiple'&$top=4&$skip=1&$format=json";
String accountKey = "HEPgn2ahb407EMW/j5TXKs5umkO6VDlb8anWMq+O2=";
byte[] accountKeyBytes = Base64.encode((accountKey + ":" + accountKey).getBytes());
String accountKeyEnc = new String(accountKeyBytes);
URL urlb = new URL(bingUrl);
URLConnection urlConnection =urlb.openConnection();
urlConnection.setRequestProperty("Authorization","basic " + accountKeyEnc);


但这不起作用...这里的帐户密钥不实际

最佳答案

不久前,我回答了类似的问题,此代码实际上有效:Bing Search API Azure Marketplace Authentication in Java

我看到的第一个问题是您正在调用Base64.encode,它实际上应该是:Base64.encodeBase64。并且您还可以尝试将basic更改为Basic(在setRequestProperty调用中)吗?

这些更改以及正确的帐户密钥应可以解决此问题。

07-26 09:27
查看更多