I/O异常(java.net.SocketException)
我一直在尝试向HTTPS站点发出GET请求。出于测试目的,我将代码定向到StackOverflow上其他地方的一个示例。我生成了一个密钥库,代码成功地加载了该文件并正确地(据我所知)创建了CloseableHttpClient 代码一直执行,直到我在输出窗口中看到“执行请求”消息。然后它挂起60秒(HttpGet的标准超时),并抛出以下错误: 2016年2月24日下午5:01:58 org.apache.http.impl.execchain.RetryExec execute 信息:处理对{s}->的请求时捕获I/O异常(java.net.SocketException):连接重置 2016年2月24日下午5:01:58 org.apache.http.impl.execchain.RetryExec execute 信息:正在重试对{s}->https:httpbin.org:443的请求 我尝试过生成一个新的密钥库,以及不同的SSLSocket设置(比如忽略所有证书),但我总是遇到相同的错误。我确信我在生成密钥/证书时犯了一个错误,但我似乎无法确定在哪里。完整代码如下 编辑:我正在使用NetbeansI/O异常(java.net.SocketException),java,ssl,netbeans,https,get,Java,Ssl,Netbeans,Https,Get,我一直在尝试向HTTPS站点发出GET请求。出于测试目的,我将代码定向到StackOverflow上其他地方的一个示例。我生成了一个密钥库,代码成功地加载了该文件并正确地(据我所知)创建了CloseableHttpClient 代码一直执行,直到我在输出窗口中看到“执行请求”消息。然后它挂起60秒(HttpGet的标准超时),并抛出以下错误: 2016年2月24日下午5:01:58 org.apache.http.impl.execchain.RetryExec execute 信息:处理对{s
// Trust own CA and all self-signed certs
SSLContext sslcontext = SSLContexts.custom()
.loadTrustMaterial(new File("src/keystore.jks"), "password".toCharArray(),
new TrustSelfSignedStrategy())
.build();
// Allow TLSv1 protocol only
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext,
new String[] { "TLSv1" },
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
CloseableHttpClient httpclient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.build();
try {
HttpGet httpget = new HttpGet("https://httpbin.org/ip");
System.out.println("Executing request " + httpget.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httpget);
try {
HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
EntityUtils.consume(entity);
} finally {
response.close();
}
} finally {
httpclient.close();
}
你设法解决了吗?我面临着类似的问题。