如何使用 android sdk 从 https 服务器获取响应?

发布于 2024-09-14 21:56:23 字数 135 浏览 2 评论 0原文

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

I have a problem of ssl exception when i upload data to a https server. It uploaded the data to the server correctly but when i get the response after uploading it throws an exception of ssl certificate is not trusted. I'm using the SAX parser for parsing xml file and i am using httppost method().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放飞的风筝 2024-09-21 21:56:23

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

检查此选项,您将在不检查证书的情况下找到另一个有用的示例...

https 连接 Android

you have to add a new scheme to accept Secure site connections

check this, and there you will find another useful sample without checking the cetificate...

Https Connection Android

套路撩心 2024-09-21 21:56:23

Android 附带了 apache commons http 库。设置 https post 请求非常简单:

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,但我的公共 http 文档会有所帮助:

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506

Android comes with the apache commons http library included. Setting up a https post request is quite easy:

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 uses a version 4.x of the commons http library as all versions below 4.0 are out of their lifecycle.

I can't tell exactly how to register a self-signed certificate to the HttpClient, but mybe the commons http documentation helps:

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文