2012-03-30 158 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