"Memo": requestheaders is the cause of header loss when HTTP webrequest is submitted in POST.

Source: Internet
Author: User

"Memo": requestheaders is the cause of header loss when HTTP webrequest is submitted in POST.

Recently, when HttpWebRequest-helper class is completed, Headers are always lost in post json data ).

 

 

 

HttpWebRequest post json data, which consists of the following steps:

> Convert JSON to byte [].

> Get the write stream from HttpWebRequest. GetRequestStream.

> Write byte [] to this Stream.

 

Similar operations, including file upload and POST form-all must be converted to byte []

 

 

 

Core considerations:

Do not set the HttpWebRequest. ContentLength field. Manually setting this field will lead to the loss of the Header (especially the loss of custom headers ].

 

 

 

 

I hope that other friends with similar problems will not take detours.

> In the past two days, I have searched more than one hundred webpages for the BUG of header loss, and there is no answer.

> Decompiled the. Net underlying class library to check if Microsoft does not allow custom headers.

> In the end, such a simple line of code is a waste of three days.

 

 

Shu Xiaolong InkFx

 

Related Article

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.