An http request to any site throws a SocketTimeoutException. What could this be related to?
public class Main {
public static void main(String[] args) {
try {
HttpURLConnection connection = (HttpURLConnection) new URL("https://coderlessons.com/tutorials/java-tekhnologii/uznaite-jsoup/jsoup-kratkoe-rukovodstvo").openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(2000);
connection.setReadTimeout(2000);
connection.connect();
if(HttpURLConnection.HTTP_OK == connection.getResponseCode()) {
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String str = reader.readLine();
while (str != null) {
System.out.println(str);
str = reader.readLine();
}
reader.close();
}
else{
System.out.println("Error " + connection.getResponseCode());
}
connection.disconnect();
}
catch (MalformedURLException ex){
ex.printStackTrace();
}
catch (IOException ex){
ex.printStackTrace();
}
}
}
I tried to connect to the server via URLConnection, but the Connectexception exception is caught