您好,感谢您的宝贵时间:
背景:
我有点“继承”了这个框架,并且在“背景”中提到的内容是一成不变的,甚至更糟,由于某些原因我无法更改它们。
问题:
(仅在调试过程中!)使用无效的安全证书将HTTP Post请求发送到(特定的)URL后,Webdriver会初始化,但实际上访问任何网站的速度非常慢。有时甚至终止连接。
浏览器左下角显示的消息是建立安全连接(对于Chrome)和执行TLS握手(对于Firefox)
这仅在远程调试期间发生。
其他信息:
httpclient相关内容的实现
该代码正在运行,我只是对其一部分进行了裁剪以仅保留相关部分:
httpClient SSLContext sslContext = getSSLContext();
private SSLContext getSSLContext() {
try {
return SSLContexts.custom()
.loadTrustMaterial(null, new TrustSelfSignedStrategy())
.build();
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
throw new RuntimeException("Could not create custom SSLContext: ", e);
}
}
SSLConnectionSocketFactory sslConnectionSocketFactory = getSslConnectionSocketFactory(sslContext);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create()
.setSSLSocketFactory(sslConnectionSocketFactory)
.setDefaultCredentialsProvider(getConfiguredCredentialsProvider())
.build();
sendPost
public CustomHttpResponse sendPost(String url, HttpEntity httpEntity) {
HttpPost httpPost = new HttpPost(url);
int statusCode;
String responseString;
if (httpEntity != null) {
httpPost.setEntity(httpEntity);
}
CloseableHttpResponse closeableHttpResponse = null;
try {
closeableHttpResponse = httpClient.execute(httpPost);
HttpEntity responseEntity = closeableHttpResponse.getEntity();
responseString = EntityUtils.toString(responseEntity);
statusCode = closeableHttpResponse.getStatusLine().getStatusCode();
} catch (IOException exception) {
throw new RuntimeException("Unable to close or execute a POST connection: ", exception);
} finally {
try {
closeableHttpResponse.close();
} catch (IOException e) {
//exceptionHandling
}
}
if (statusCode == 0 && responseString == null) {
throw new RuntimeException("StatusCode or responseString is null!");
}
return new CustomHttpResponse(statusCode, responseString);
}