Answer the question
In order to leave comments, you need to log in
How to solve this problem: HostConnection::get() New Host Connection established?
package data;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import Util.Utils;
/**
* Created by Evgeny on 10/25/16.
*/
public class WeatherHttplClient {
public String getWeatherData(String place){
HttpURLConnection connection = null;
InputStream inputStream = null;
try {
connection = (HttpURLConnection) (new URL(Utils.BASE_URL+place)).openConnection();
connection.setRequestMethod("GET");
connection.setDoInput(true);
connection.connect();
//Read the response
StringBuffer stringBuffer = new StringBuffer();
inputStream = connection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line + "\r\n");
}
inputStream.close();
connection.disconnect();
return stringBuffer.toString();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
Answer the question
In order to leave comments, you need to log in
You have the wrong host. You are trying to reach www.google.byMinsk. Hence the error.
PS By the way, the error description begins further with the line: java.net.UnknownHostException...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question