HTTPS POST 在 Gingerbread 上工作但在 Froyo 上不起作用?
这是有问题的代码部分:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论