信任所有证书? X509证书
我有以下代码通过HTTPS连接,但在连接尝试期间出现跟随错误。信任所有证书? X509证书
WARN/System.err的(9456):javax.net.ssl.SSLHandshakeException: org.bouncycastle.jce.exception.ExtCertPathValidatorException:无法验证证书的签名。
我该如何解决这个问题? 信任所有证书?我怎么做? 这将是没有问题,因为我只连接到同一台服务器。 FY我在应用程序中已经实现了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());
彼得嗨,
THX你的答案,我也跟着您的意见和无法验证消息已不存在。但现在我收到以下消息:
09-26 23:47:20.381:WARN/ResponseProcessCookies(10704):Cookie被拒绝:“BasicClientCookie [version = 0,name = ObFormLoginCookie,domain = www.kpn.com ,路径= /网络/限制/形式?formelement = 512663,期满=空]”。非法路径属性“/ web/restricted/form?formelement = 512663”。原始路径:“/ web/restricted/form/formelement = 512663” 09-26 23:47:20.461:WARN/Response(10704):状态行:[email protected]
所以标题中的东西似乎是错的?
不信任所有证书,这是一个非常,非常糟糕的主意。用你的服务器证书创建一个密钥库,放入应用程序的原始资产,并将其加载到HttpClient的SSLSocketFactory中。然后在SchemeRegistry
中将此工厂注册为https。
嗨,彼得,请看看我上面编辑过的信息.. 谢谢你提前。 – Lars
正在发送的cookie与cookie中定义的路径不匹配。 Thre是一个“?”代替 ”/” –