【发布时间】:2012-02-20 10:39:47
【问题描述】:
我有一个要移植到 ICS 的 Gingerbread Android 应用程序。此应用程序与发送 HTTP POST 的 Web 服务器通信。我的应用程序在 Gingerbread 上运行良好。但是,在将其移植到 ICS 后,我遇到了问题。我发现我的应用程序发送的 POST 请求实际上已更改为 GET。
有趣的是,Android 实际上报告说确实使用了 POST。
URL oURL = new URL(sURL);
HttpURLConnection oHTTPConnection = (HttpURLConnection)(oURL.openConnection());
oHTTPConnection.setDoInput(true);
oHTTPConnection.setDoOutput(true);
oHTTPConnection.setRequestMethod("POST");
// set headers...
int nResponse = oHTTPConnection.getResponseCode();
String sMethod = oHTTPConnection.getRequestMethod(); // Returns "POST"
但是,服务器会另说。我修改了 Web 服务器应用程序以检查它接收到的请求方法,然后将此值放入它发送回我的 Android 应用程序的响应正文中。我在 Android 应用程序上收到的是“GET”。
我曾尝试将 HttpClient 与 HttpPost 一起使用,但我遇到了同样的问题。
正如我所提到的,我在 Gingerbread 中没有这个问题。另外,我从另一个线程中读到了一个类似(但相反)的问题,它也只发生在 ICS 中:Android 4.0 ICS turning HttpURLConnection GET requests into POST requests。
有其他人经历过吗?谁能帮我解决这个问题?
提前致谢!
赖
【问题讨论】:
-
你试过加
oHTTPConnection.setRequestProperty("Content-Type","application/x-www-form-urlendcoded");吗? -
@MagnusJohansson 是的,我已经尝试过那个,但是,没有运气。 :/ 无论如何谢谢...
标签: java android httpurlconnection android-4.0-ice-cream-sandwich