2012-03-30 78 views
0

基本上,我試圖讓我的應用程序執行以下命令執行一個POST請求在Android的

捲曲-i -X POST -d 「用戶= USER &通= PASShttps://websitehere.com

但我不明白迄今爲止發現的解決方案。如果我使用HttpPost發佈nameValuePairs,這些應該是什麼?

我還在httpclient.execute(httppost)時收到信息ssl-certificate-not-trusted-error的IOException;命令完成。

public void postData(String userString, String passString) { 

     HttpClient httpclient = new DefaultHttpClient(); 
     HttpPost httppost = new HttpPost("https://websitegoeshere.com"); 
     try { 
      // Add your data 
      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 
      nameValuePairs.add(new BasicNameValuePair("user", userString)); 
      nameValuePairs.add(new BasicNameValuePair("pass", passString)); 
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8)); 


      response = httpclient.execute(httppost); 



     } catch (ClientProtocolException e) { 
      e.printStackTrace(); 
     } catch (IOException e) {    
      e.printStackTrace(); 
     } 
    } 
+0

你的心不是證書有效。在此處進行測試:https://www.digicert.com/help/index.htm – blindstuff 2012-03-30 19:43:00

+0

您鏈接的網站稱其有效。 – Corith 2012-03-30 22:25:08

+0

某些證書不被android所喜歡,因爲雖然有效,但缺少一些中級證書,請與您的證書提供商聯繫。 – blindstuff 2012-03-30 23:21:29

回答

1

如果你想忽略SSL證書錯誤,因爲你信任該網站,則需要提供自己的TrustManager其信任的所有證書。

參考:HTTPS and self-signed certificate issue

+0

感謝您的回覆。該網站的所有者聲稱有一個有效的工作,我可以做錯了什麼? – Corith 2012-03-30 20:32:13

0

也許嘗試這種手段來驗證:

HttpPost post = new HttpPost("https://websitegoeshere.com"); 
try { 
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password); 
    post.addHeader(new BasicScheme().authenticate(creds, post)); 
} catch (AuthenticationException e) { 
    // Handle Exception 
} 
+0

沒有工作,謝謝你的嘗試。 – Corith 2012-03-30 21:36:43