我将数据上传到https服务器时遇到ssl异常问题。它正确地将数据上传到服务器但是当我在上传后得到响应时抛出了一个ssl证书不受信任的例外。我正在使用SAX解析器来解析xml文件,我正在使用httppost方法()。
答案 0 :(得分:1)
答案 1 :(得分:0)
Android自带了apache commons http库。设置https发布请求非常简单:
HttpPost post = new HttpPost("https://yourdomain.com/yourskript.xyz");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("postValue1", "my Value"));
nameValuePairs.add(new BasicNameValuePair("postValue2", "2nd Value"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
String responseText = EntityUtils.toString(entity);
Android使用commons http库的4.x版本,因为4.0以下的所有版本都在其生命周期之外。
我无法确切地知道如何向HttpClient注册自签名证书,但mybe the commons http文档有帮助:
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506