bekommen kann ich nicht kippe, irgend etwas von bing img Suche api bekommen nur zurück, hier ist die Details dieses api, warum ich etwas zurück für bing API
seit Httpclient so verwende ich veraltet HttpURLConnection, Kann mir jemand sagen, was mit meinem Code nicht stimmt?
alle params und der schlüssel sind gut, ich habe auf der website getestet.
danke!
public void run() {
HttpURLConnection connection = null;
try {
URL url = new URL("https://api.cognitive.microsoft.com/bing/v5.0/images/search");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setConnectTimeout(8000);
connection.setReadTimeout(8000);
connection.setUseCaches(false);
connection.setRequestProperty("Ocp-Apim-Subscription-Key", "562eaaada4b644f2bea31a454f26d905");
OutputStream out = connection.getOutputStream();
DataOutputStream params =new DataOutputStream(out);
params.writeBytes("q=dog&count=10&offset=0&mkt=en-us&safeSearch=Moderate");
out.close();
connection.connect();
InputStream in = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
Message message = new Message();
message.what = SHOW_RESPONSE;
message.obj = response.toString();
handler.sendMessage(message);
} catch (Exception e) {
// TODO: handle exception
} finally {
if (connection != null) {
connection.disconnect();
}
}
}