【发布时间】:2015-07-07 10:21:26
【问题描述】:
我用代码
public static int getResponseCode(String urlString) throws MalformedURLException, IOException {
URL u = new URL(urlString);
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
huc.setRequestMethod("GET");
huc.connect();
return huc.getResponseCode();
}
获取响应代码。当我运行代码时,我得到一个异常 java.net.ConnectException:连接超时 在 java.net.PlainSocketImpl.socketConnect(Native Method)
我打印了导致此错误的 URl,然后将其加载到浏览器中。链接已加载,但过了一段时间,大约 2 分钟。未返回状态码的原因可能是什么?我该如何处理这种情况?
感谢您的帮助!
沙里
【问题讨论】:
-
你能发布错误信息吗?
-
是的.. java.net.ConnectException:连接超时在 java.net.PlainSocketImpl.socketConnect(Native Method)
-
可以发网址吗?
-
quote2sales.com 是网址
标签: java selenium-webdriver httpurlconnection connectexception