Tring использовать API поиска Бинга лазурного marketpalce с Java У меня есть этот код:поиск апите Бинг лазурного marketpalce с Явой
import org.apache.commons.codec.binary.Base64;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
public class BingAPI2 {
public static void main(String[] args) throws Exception{
BingAPI2 b = null;
b.getBing();
}
public static void getBing() throws Exception {
HttpClient httpclient = new DefaultHttpClient();
try {
String accountKey = "myAccountKey=";
byte[] accountKeyBytes = Base64.encodeBase64((":" + accountKey).getBytes());
String accountKeyEnc = new String(accountKeyBytes);
HttpGet httpget = new HttpGet("https://api.datamarket.azure.com/Data.ashx/Bing/Search/Web?$Query=%27Datamarket%27&$format=json");
httpget.setHeader("Authorization", "Basic <"+accountKeyEnc+">");
System.out.println("executing request " + httpget.getURI());
// Create a response handler
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httpget, responseHandler);
System.out.println("----------------------------------------");
System.out.println(responseBody);
System.out.println("----------------------------------------");
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
}
}
Я получаю сообщение об ошибке:
Исключения в потоке " main " org.apache.http.client.HttpResponseException: Тип авторизации , который вы предоставили, не поддерживается. Только Basic и OAuth поддерживаются