1

I am using HttpWebRequest to send requests in c#

The request should be like this:

POST https://website.com/file HTTP/1.1
Host: api.website.com
User-Agent: useragent
Content-Length: 81
Accept: */*
Accept-Language: en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Accept-Encoding: gzip, deflate
Connection: keep-alive

but it is showing like this:

POST https://website.com/file HTTP/1.1
Accept-Encoding: gzip, deflate
Accept-Language: en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5
User-Agent: useragent
Accept: */*
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: api.website.com
Content-Length: 97
Connection: Keep-Alive

I tried to search on how to change order of httpwebrequest but could not find anything.

circler
  • 359
  • 1
  • 3
  • 16
  • 6
    If your server depends on the orders of the *headers*, I'd argue it's broken. I wouldn't *expect* the order to be guaranteed or meaningful - why is your code sensitive to it? – Jon Skeet Jul 15 '13 at 15:51
  • you wont to change order of headers ? Why is that important ? – Antonio Bakula Jul 15 '13 at 15:52
  • the web server has a security check to check the order of the headers. so i have to keep them that way. – circler Jul 15 '13 at 15:55
  • 2
    Show them this part of the RFC: [_" The order in which header fields with differing field names are received is not significant."_](http://tools.ietf.org/html/rfc2616#page-32). – CodeCaster Jul 15 '13 at 16:00
  • Duplicate of [Is it possible to change headers order using HttpWebRequest?](http://stackoverflow.com/questions/521977/is-it-possible-to-change-headers-order-using-httpwebrequest), where the answer is: no, if you really need this, write a HTTP client yourself using sockets. – CodeCaster Jul 15 '13 at 16:00
  • hmm, yea the writing http client using sockets is my option, but trying to find if there is anything less time consuming. Is there any open source http client source that i can modify to my needs ? – circler Jul 15 '13 at 16:09
  • @circler: Probably not. There might be clients which coincidentally maintain the order of headers, but it's unlikely that any of them *guarantee* the order of headers. Since this is custom functionality that's not part of the standard, you're looking at writing a custom implementation. – David Jul 15 '13 at 16:12

0 Answers0