HTTPS POST 在 Gingerbread 上工作但在 Froyo 上不起作用?

发布于 2024-12-04 07:32:03 字数 1015 浏览 0 评论 0原文

这是有问题的代码部分:

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
HttpClient mHttpClient = new DefaultHttpClient();
nameValuePairs.add(new BasicNameValuePair(strName1, strValue1));
nameValuePairs.add(new BasicNameValuePair(strName2, strValue2));
post = new HttpPost(strPostURL);
post.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
HttpResponse response = mHttpClient.execute(post);

strPostURL 以“https://”开头。

此代码在最后一行失败 - 引发以下异常:

WARN/System.err(7151): org.apache.http.client.ClientProtocolException
WARN/System.err(7151): Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response

我已针对 Froyo (2.2) 和 Gingerbread (2.3.3) 平台尝试了此代码,但它仅适用于 2.3.3。在模拟器上也有相同的结果。

当我在测试服务器上尝试常规 HTTP POST 时,Froyo 和 Gingerbread 都工作正常,因此 HTTPS 一定存在某些特殊情况导致了此问题。

如果重要的话,我还在代码的后面部分使用 httpmime-4.1.2.jar 来处理多部分附件,因此这个 jar 包含在我的构建路径中。

有人可以指出我做错了什么吗?

Here's a section of code in question:

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
HttpClient mHttpClient = new DefaultHttpClient();
nameValuePairs.add(new BasicNameValuePair(strName1, strValue1));
nameValuePairs.add(new BasicNameValuePair(strName2, strValue2));
post = new HttpPost(strPostURL);
post.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
HttpResponse response = mHttpClient.execute(post);

strPostURL begins with "https://".

This code fails on the last line - throws the following exception:

WARN/System.err(7151): org.apache.http.client.ClientProtocolException
WARN/System.err(7151): Caused by: org.apache.http.ProtocolException: The server failed to respond with a valid HTTP response

I've tried this code against both Froyo (2.2) and Gingerbread (2.3.3) platform and it only works on 2.3.3. Same results on emulators as well.

When I tried the regular HTTP POST on my test server, both Froyo and Gingerbread works fine, so there must be something particular about HTTPS that is causing this issue.

If matters, I am also using httpmime-4.1.2.jar for handling multi-part attachments at a later part of the code, so this jar is included in my build path.

Could someone kindly point out what am I doing wrong please?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文