Java, httpurlconnection, and set the content length

I am setting the length of the content in my httpurlconnection for put

urlConnection.setRequestProperty("Content-Length","" + responseJSONArray.toString(2).getBytes("UTF8").length);

The actual number of bytes is 74 However, when I query the content length of urlconnection, I return - 1 Why? Why are the lengths not equal (given that I set this)?

I have to set the content length because I received a 411 response from the server

(in addition, in sun examples, I see that the second parameter of setrequestproperty is of type int instead of string, which seems strange.)

Solution

You shouldn't set this head yourself Use setfixedlengthstreamingmode() or setchunkedtransfermode()

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>