- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
如何解决“SSLHANDSHAKE 异常”以及如何在 httpClient post 方法中维护“Cookies”。我已将一些 session 参数“nameValuePair”和 cookie 传递给 http 客户端发布方法。在“httpClient.executeMethod(postMethod)”中发布所有参数后,它不会用于下一个“postMethod.getResponseBodyAsString();”在它显示一些异常之后。
try {
initialState = new HttpState();
httpClient = new HttpClient();
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(25000);
httpClient.getParams().setParameter("http.socket.timeout", new Integer(25000));
httpClient.getHostConfiguration().setProxy("127.0.0.1",8888);
// Properties systemProperties = System.getProperties();
// systemProperties.put("proxySet", "true");
// systemProperties.put("http.proxyHost", "127.0.0.1");
// systemProperties.put("http.proxyPort", 8888);
try {
httpClient.getParams().setAuthenticationPreemptive(true);
// httpClient.getState().setProxyCredentials(null, null, new UsernamePasswordCredentials(null, null));
} catch (Exception ex) {
ex.printStackTrace();
}
//httpClient.getParams().setCookiePolicy(CookiePolicy.ACCEPT_ALL);
cookies = httpClient.getState().getCookies();
} catch (Exception ex) {
}
try {
postMethod = new PostMethod(pageUrl);
postMethod.addParameter("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3");
postMethod.addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
postMethod.addRequestHeader("Accept-Language", "en-us,en;q=0.5");
postMethod.addRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
postMethod.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
postMethod.addRequestHeader("KeepAlive", "true");
postMethod.setFollowRedirects(FollowRedirect);
postMethod.setDoAuthentication(DoAuthentication);
if (referer != null) {
postMethod.addRequestHeader("referer", referer);
}
if (cookieArr != null) {
cookies = new Cookie[cookieArr.length];
for (int i = 0; i < cookieArr.length; i++) {
cookies[i] = new Cookie(".linkedin.com", cookieArr[i][0], cookieArr[i][0], "/", null, true);
}
}
initialState.addCookies(cookies);
int postDataLength = postData.length;
NameValuePair[] nameValuePair = new NameValuePair[postDataLength];
for (int i = 0; i < postDataLength; i++) {
nameValuePair[i] = new NameValuePair(postData[i][0], postData[i][1]);
}
postMethod.addParameters(nameValuePair);
httpClient.executeMethod(postMethod);
cookies = httpClient.getState().getCookies();
pageSouce = postMethod.getResponseBodyAsString();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
postMethod.releaseConnection();
}
但是运行时出现如下异常:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
最佳答案
看起来服务器没有有效的证书。可能服务器的 Root-CA 不包含在您的 java cacert 中。
也许这会有所帮助:http://blogs.oracle.com/gc/entry/unable_to_find_valid_certification
关于java - 如何解决 SSLHandshake 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8837391/
我正在使用 SSL 连接,对于某些用途,当它从 Java 库中抛出时,我需要找出警报类型及其严重性。 sslException.getAlertLevel() or sslException.getA
如何解决“SSLHANDSHAKE 异常”以及如何在 httpClient post 方法中维护“Cookies”。我已将一些 session 参数“nameValuePair”和 cookie 传递
svn: OPTIONS of 'https://comp20006.eng.unimelb.edu.au/svn/pochen': SSL handshake failed: Secure conn
当我尝试在 Apple Mail 中配置我的企业邮件帐户 (Exchange) 时,我可以在控制台中看到以下错误日志。但是在 Outlook 2011 邮件客户端中配置相同的帐户时我看不到此错误。当我
我有一组用 Java 编写的“包装器”服务,运行在 AWS 上的 Tomcat 8 上,它们调用客户端的一组 MIME 服务。当我尝试调用他们的服务时,我得到一个 SSLHandshakeExcept
我正在使用 iOS 应用程序,在 iOS 9 中测试时出现以下错误。 CFNetwork SSLHandshake failed (-9806) NSURLSession/NSURLConnec
我有带有 REST API 的自定义硬件设备。设备具有自签名根证书。我正在尝试进行简单的 GET 调用,但我的所有请求都失败了: CFNetwork SSLHandshake failed (-980
我用 Java 程序(使用 HttpUrlConnection)向网站发送 http 请求并从那里下载文件。 该网站是“https”并使用证书。 当我尝试运行我的代码时出现异常: cause java
有 iOS 9 beta 1 的人有这个问题吗? 我使用标准 NSURLConnection 连接到网络服务,一旦调用网络服务,我就会收到以下错误。这目前在 iOS 8.3 中工作 可能的测试错误?任
我在从 Java 发送邮件时遇到以下异常。 31/03 14:06:19:571 INFO [ ] IBSUtils sendMailfromsmtp() MessagingException in
2015-11-04 15:17:23.236 Testing[2504:80857] CFNetwork SSLHandshake failed (-9824) 2015-11-04 15:17:2
有 2 个 Websphere 服务器。第一个是客户端,第二个是服务器 (8.5.5.13)。 最终用户向客户发出 SOAP 请求。客户端接收请求,进行一些处理,然后向服务器发出REST 请求。 当服
我在我的控制台 CFNetwork SSLHandshake failed (-9806) 中收到 xCode 的错误日志。 我如何找出哪个请求导致失败的日志。 当我的应用程序启动时,有很多第三方请求
有人遇到过这个问题吗?我的应用程序工作正常,当我更新到最新的 Xcode 时,这个错误开始出现。这些是错误: CFNetwork SSLHandshake failed (-9806) NSURLSe
我正在尝试修复 CFNetwork SSLHandshake 失败 (-9806) 警告。我的应用程序运行良好,但是当我在设备中通过 Xcode 运行应用程序时,应用程序崩溃了。我在 .plist 中
使用 iOS 9 beta 1 的人遇到过这个问题吗? 我使用标准 NSURLConnection 连接到网络服务,一旦调用网络服务,我就会收到以下错误。这目前在 iOS 8.3 中有效 可能是测试版
有时我的代码中出现 CFNetwork SSLHandshake failed -(9806),但我不确定为什么会这样,因为我的代码运行顺利,除非我在 iOS 中运行它6 然后在 iOS 7 64 位
使用 iOS 9 beta 1 的人遇到过这个问题吗? 我使用标准 NSURLConnection 连接到网络服务,一旦调用网络服务,我就会收到以下错误。这目前在 iOS 8.3 中有效 可能是测试版
我正在开发 Apple Pay POC,在此过程中,我尝试使用休息服务,但很难通过 Java 代码连接到该服务器。 但是,使用下面的curl命令可以正常工作。 curl -v --cert publi
我在登录应用程序时在我的 ios 应用程序中收到 CFNetwork SSL Handshake failed(-9807)。 我的应用程序使用的是 Xcode 7.3 版。 我认为这个问题是由于 s
我是一名优秀的程序员,十分优秀!