Bug 1512 - HttpWebRequest not encode Header after writing POST's body
Summary: HttpWebRequest not encode Header after writing POST's body
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 2.10.x
Hardware: PC All
: --- normal
Target Milestone: Untriaged
Assignee: Gonzalo Paniagua Javier
Depends on:
Reported: 2011-10-15 14:48 UTC by Natthawut Kulnirundorn
Modified: 2012-01-10 16:00 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

.cs Source, PCAP files captured, and binary built from VS2010 (6.91 KB, application/octet-stream)
2011-10-15 14:48 UTC, Natthawut Kulnirundorn

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Natthawut Kulnirundorn 2011-10-15 14:48:21 UTC
Created attachment 704 [details]
.cs Source, PCAP files captured, and binary built from VS2010


This is related to System.Net.HttpWebRequest class.

When using "POST" Method and having written data to GetRequestStream(), after this if we add an HTTP Header [using request.Headers.Add("key","value")], this header will not be sent in actual HTTP request. I have verified this using tcpdump/Wireshark.

To reproduce:
  1) Build from 'HttpHeaderTest.cs' from attached archive file.
  2) Run a TCP traffic sniffer, e.g. $ tcpdump -i eth0 -s 0 -w output.pcap
  3) Run the test app $ mono HttpHeaderTest.exe. It will send a POST to mono-project.com and exit shortly
  4) End the network capture.
  5) Check the HTTP headers. There is no custom header we added.

Expected result:
  Our custom header should be included in the HTTP header. With MS .NET Framework, the header is included [see windows_net40_vs2010.pcap]

Other affected versions:
  Found this in 2.6.7 as well.

  By adding Header before writing POST's body using 'GetRequestStream()', the header is encoded correctly. 

Comment 1 Gonzalo Paniagua Javier 2011-10-16 02:02:27 UTC
I have fixed this issue in master/8e67b8c2.
If there are no problems with this change, I will push it to the mono-2-10 branch in ~1 month.

I will leave this issue open until then.
Comment 2 Natthawut Kulnirundorn 2011-10-16 03:29:17 UTC
Thanks for the swift response, Gonzalo.
Comment 3 Gonzalo Paniagua Javier 2012-01-10 16:00:34 UTC
Applied to mono-2-10