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 a27d11ddef
commit 778bd6c98f

View File

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