即使我检查了以前在 java 中针对 web 搜索的 azure 身份验证的答案,但不知何故,我仍然得到 HTTP 错误代码:401,即使帐户密钥与我在 Windows Azure Marketplace 中的配置文件中的密钥完全相同。我尝试生成一个新的,但也没有用。
因此,任何帮助将不胜感激。
这是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:服务器返回 HTTP 响应代码:401 用于 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 ) 在 queryengines.WebSample.main(WebSample.java:19)