【问题标题】:How to get a response from a https server using android sdk?如何使用 android sdk 从 https 服务器获取响应?
【发布时间】:2010-08-13 15:41:14
【问题描述】:

当我将数据上传到 https 服务器时,我遇到了 ssl 异常问题。它正确地将数据上传到服务器,但是当我在上传后收到响应时,会引发 ssl 证书不受信任的异常。我正在使用 SAX 解析器来解析 xml 文件,并且我正在使用 httppost 方法()。

【问题讨论】:

  • 如果您的 https 服务器没有使用签名的 ssl 证书与之通信将非常困难
  • 是的,这非常困难,但我昨天晚上已经完成了。这样做需要很多时间。如果您愿意,请给我发送电子邮件 ID

标签: android https


【解决方案1】:

您必须添加一个新方案才能接受安全站点连接

检查这个,你会发现另一个有用的样本而不检查证书...

Https Connection Android

【讨论】:

  • 我见过这个但是只有当我想从服务器获取数据而不是发布数据时才会有帮助
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    相关资源
    最近更新 更多