问候,
我正在开发一个Android应用程序,需要通过https打开一个url(带有POST参数)并获得响应.
我有一个自签名证书的复杂性增加了.我还需要接受cookies.
任何人都有关于从哪里开始的任何想法?
提前谢谢了,
Android附带了apache commons http库.设置https发布请求非常简单:
HttpPost post = new HttpPost("https://yourdomain.com/yourskript.xyz"); ListnameValuePairs = new ArrayList (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