The HTTP Request Header does not contain Content-Length.

Source: Internet
Author: User

I encountered a problem during the development of j2m3. my HTTP request does not have the Content-Length attribute. The server needs the value of this attribute.

Solution:

Remove the flush statement from the program.

 

Based on information from various parties, I learned:

Generally, the HTTP request header contains the Content-Length attribute. The value is the length of the sent content. The recipient (browser or server side) will wait for the content to be completely transmitted, and then retrieve the content based on the Content-Length value. However, if transfer-encoding is set to chunked, no Content-Length attribute exists in the HTTP request header. Because transfer-encoding is chunked, it means that the content will be sent in one piece, and the recipient does not need to read the content until all the content is transmitted. In this case, Content-Length cannot be calculated, so this attribute is unavailable.


There are two ways to make the HTTP request transmit content in chunked mode.

One is to set the length of the server's Io buffer so that the server will automatically flush the content in the buffer.

The other is to manually call the flush function in Io. For example, out. Flush () is used in Java ();


Therefore, if your HTTP request uses chunked encoding, and this is not what you want, you can remove the flush statement in the program and there should be no problem.

 

After this is done, there is no problem in eclipse. But the same code is still in chunked mode in netbeans.

 

Later, I added the project's simulator Platform
Changed to Sun's wtk. No problem. I have no time to study the xuanjicang. Use it first.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.