网址连接代码
URL urlToRequest = new URL(URL);
urlConnection = (HttpURLConnection)urlToRequest.openConnection();
urlConnection.setRequestProperty("Accept", "application/xml");
urlConnection.setRequestProperty("Content-Type", "application/xml");
urlConnection.setRequestProperty ("Authorization",getB64Auth("admin","admin"));
urlConnection.setConnectTimeout(CONNECTION_TIMEOUT);
// urlConnection.setReadTimeout(CONNECTION_TIMEOUT_SOCKET);
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
String response = readStream(in);
return response;
setConnectTimeout()
功能不起作用。我需要解决方案,如何设置connection TimeOut
。
答案 0 :(得分:0)
尝试读取超时。
urlConnection.setReadTimeout(READ_TIMEOUT);
您是否正在捕获SocketTimeOut和ConnectionTimout异常?