HttpUrlConnection reverts Content-Length=0 on POST unless doOutput is set to true

This commit is contained in:
adriancole 2013-03-24 20:58:29 -07:00
parent a7dc94ea77
commit cd79a9d876
1 changed files with 5 additions and 0 deletions

View File

@ -231,6 +231,11 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
protected void writeNothing(HttpURLConnection connection) { protected void writeNothing(HttpURLConnection connection) {
if (!HttpRequest.NON_PAYLOAD_METHODS.contains(connection.getRequestMethod())) { if (!HttpRequest.NON_PAYLOAD_METHODS.contains(connection.getRequestMethod())) {
connection.setRequestProperty(CONTENT_LENGTH, "0"); connection.setRequestProperty(CONTENT_LENGTH, "0");
// support zero length posts.
if ("POST".equals(connection.getRequestMethod())) {
connection.setFixedLengthStreamingMode(0);
connection.setDoOutput(true);
}
} }
} }