HttpWebRequest and ordering of headers

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
 
N

Nick Jacobsen

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
 
S

Steve Binney

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top