2011-09-26 192 views
1

我有以下代碼通過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]

所以標題中的東西似乎是錯的?

回答

1

不信任所有證書,這是一個非常,非常糟糕的主意。用你的服務器證書創建一個密鑰庫,放入應用程序的原始資產,並將其加載到HttpClient的SSLSocketFactory中。然後在SchemeRegistry中將此工廠註冊爲https。

0

您需要提供您自己的TrustManager,它信任所有證書。

看到這個答案:HTTPS and self-signed certificate issue

+0

嗨,彼得,請看看我上面編輯過的信息.. 謝謝你提前。 – Lars

+0

正在發送的cookie與cookie中定義的路徑不匹配。 Thre是一個「?」代替 」/」 –