我正在使用以下代码从 web 服务获取数据。但这种行为是出乎意料的。当我通过代码时,它会提供 7-8 次数据,但在连接超时错误之后。有什么解决办法??
URL url = new URL(webPage);
URLConnection urlConnection = url.openConnection();
System.out.println("Connection Timeout ===== "+urlConnection.getConnectTimeout());
urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
urlConnection.setConnectTimeout(20000);
InputStream is = urlConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
例外是:java.net.SocketTimeoutException: connect timed out