Android HTTP PUT请求仅在Android 2.1上返回411错误

Android HTTP PUT请求仅在Android 2.1上返回411错误,android,http,rest,http-put,Android,Http,Rest,Http Put,我这里有一个应用程序,它向Web服务器发送HTTP PUT。代码如下所示: URL url = new URL(urlStr + "?" + encodedParameters); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("PUT"); connection.setRequestProperty("Content-Len

我这里有一个应用程序,它向Web服务器发送HTTP PUT。代码如下所示:

  URL url = new URL(urlStr + "?" + encodedParameters);
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  connection.setRequestMethod("PUT");
  connection.setRequestProperty("Content-Length", "0");
当我在Android 2.1上尝试这一点时,我最终得到了一个411错误(“需要长度”)

在安卓2.3.3及以上版本中,我得到了相同的411错误,直到我添加了最后一个“内容长度”属性。但它仍然在安卓2.1上发生


有人知道这里可能发生了什么吗?

不确定这是否可行,但可能值得尝试如下设置“内容长度”:

connection.setRequestProperty("Content-Length", Integer.toString(encodedParameters.getBytes().length));

恐怕没什么不同