Почему я получаю код ошибки http 500, когда отправляю запрос отдыхаJAVA

Программисты JAVA общаются здесь
Anonymous
Почему я получаю код ошибки http 500, когда отправляю запрос отдыха

Сообщение Anonymous »

Когда я помещаю URL в браузер, я могу получить json < /p>

http://api.openweathermap.org/data/2.5/weather?q=Rome, Italy&appid=2de143494c0b295cca9337e1e96b00e0
< /code>

Но когда я делаю это через Java с помощью http get -запроса.private String getWeather(Booking booking){
StringBuilder sb = new StringBuilder();
URL url;
try {
url = new URL("http://api.openweathermap.org/data/2.5/ ... e1e96b00e0");
System.out.println(url);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");

if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}

BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));

String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return sb.toString();
}


Подробнее здесь: https://stackoverflow.com/questions/343 ... st-request

Вернуться в «JAVA»