HttpWebRequest and ordering of headers

  • Thread starter Thread starter Steve Binney
  • Start date Start date
S

Steve Binney

The Web server I am communicating with has the requirement that the
content-type header comes before the content-disposition header. I am not
able to achieve this. When my code has the following:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(myUri);

req.ContentType = "application/x-DoCommand\r\n";

WebHeaderCollection col = new WebHeaderCollection();

col.Add("Content-Disposition: attachment; filename=\"" + textBox1.Text +
"\"\r\n");

It puts content-disposition in the header but not content-type

When I play with the order of lines of code:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(myUri);

WebHeaderCollection col = new WebHeaderCollection();

col.Add("Content-Disposition: attachment; filename=\"" + textBox1.Text +
"\"\r\n");

req.Headers = col;

req.ContentType = "application/x-DoCommand\r\n";

I get both but Content-Disposition is before Contentn-type.

How do I get type before disposition?

Steve Binney
 
Did you try:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(myUri);
req.Headers.Clear()
req.ContentType = "application/x-DoCommand"
req.Headers.Add("Content-Disposition", "attachment; filename=\"" +
textBox1.Text )

Also, a couple comments - one, you do NOT need newline after headers - .net
does that automattically, also, are you sure that the problem is that the
headers are being sent in the wrong order? to see the actual data being
sent back and forth, use a local viewing proxy like proxyTrace
(http://www.pocketsoap.com)

Nick Jacobsen
 
Nick,

Thanks for your response.

When I tried the order you suggested, I get the following (from EtherPeek)
Line 1: PUT /Upload HTTP/1.1<CR><LF>
Line 2: Content-Disposition: attachment;
filename="21"<CR><LF>
Line 3: Referer: http://192.168.0.2/<CR><LF>
Line 4: Accept: */*<CR><LF>
Line 5: User-Agent: DoCommand_Sample<CR><LF>
Line 6: Content-Length: 6<CR><LF>
Line 7: Expect: 100-continue<CR><LF>
Line 8: Connection: Keep-Alive<CR><LF>
Line 9: Host: 192.168.0.2<CR><LF><CR><LF>

The Content Type is not shown at all.

Steve

Steve
 
Back
Top