The PHP Interface (C #) does not receive data? Contentlength=-1

Source: Internet
Author: User

Problems encountered while working. The browser can view the JSON data, but the other person will not receive the data.

Finally found Contentlength=-1 found.

Find the question: why. NET program Download the Contentlength=-1?

Excerpt as follows: With the HTTP analysis tool will find that the reason is very simple, this is because some Web servers in the delivery of response content, the compression algorithm such as gzip or deflate compression of the content of the Web page, so that the content of the Web page packet size greatly reduced, thereby speeding up the network transmission, This way, the client's browser display page also accelerates. This is because of this gzip or deflate feature, so that the Web page data in the HTTP transmission will not add the ContentLength attribute in the header, so the program will retrieve the value of ContentLength by default is-1 (without gzip or Deflate feature pages will certainly contentlength specific values).

Workaround:header(' content-length: '. strlen ($json));

Just send the header before outputting the JSON data.

Of course you can also turn off the server gzip feature, not recommended.

The PHP Interface (C #) does not receive data? Contentlength=-1

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.