【发布时间】:2011-09-26 20:49:42
【问题描述】:
我有以下通过 HTTPS 连接的代码,但在尝试连接时出现以下错误。
WARN/System.err(9456): javax.net.ssl.SSLHandshakeException: org.bouncycastle.jce.exception.ExtCertPathValidatorException:无法验证证书签名。
我该如何解决这个问题? 信任所有证书?我怎么做? 没问题,因为我只连接到同一台服务器。 仅供参考,我已经在我的应用中将 EasyX509TrustManager 实现为一个类。
提前谢谢你。
try {
HttpClient client = new DefaultHttpClient();
// Setting up parameters
SchemeRegistry schemeRegistry = new SchemeRegistry();
// http scheme
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
// https scheme
schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));
HttpParams params = new BasicHttpParams();
params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
DefaultHttpClient httpClient = new DefaultHttpClient(cm, client.getParams());
// Example send HttpsPost request
final String url = "https://www.xxxx.com/web/restricted/form/formelement";
// Do the HTTPS Post
HttpPost httpPost = new HttpPost(url);
ArrayList<NameValuePair> postParameters;
postParameters = new ArrayList<NameValuePair>(2);
postParameters.add(new BasicNameValuePair("usr_name", username));
postParameters.add(new BasicNameValuePair("usr_password", password));
System.out.println(postParameters);
HttpResponse response = httpClient.execute(httpPost);
Log.w("Response ","Status line : "+ response.toString());
嗨,彼得,
谢谢您的回答,我听从了您的建议,无法验证的消息消失了。但是现在我收到以下消息:
09-26 23:47:20.381:WARN/ResponseProcessCookies(10704):Cookie 被拒绝:“BasicClientCookie[version=0,name=ObFormLoginCookie,domain=www.kpn.com,path=/web/restricted/form?表单元素=512663,到期=空]"。非法路径属性“/web/restricted/form?formelement=512663”。来源路径:“/web/restricted/form/formelement=512663” 09-26 23:47:20.461:警告/响应(10704):状态行:org.apache.http.message.BasicHttpResponse@407afb98
所以标题中似乎有问题?
【问题讨论】:
标签: android https x509certificate