Is it possible to change headers order using HttpW

2019-02-22 23:19发布

问题:

I need to change the order of headers, I'm using this:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = context.Request.HttpMethod;
request.UserAgent = context.Request.UserAgent;

The output for that is:

GET /* HTTP/1.1
User-Agent: My Server
Host: 127.0.0.1:1080

But it should be

GET /* HTTP/1.1
Host: 127.0.0.1:1080
User-Agent: My Server

Any ideas?

Thanks for your time.

EDIT: Maybe there's a way using other object ... it's also an option

回答1:

There was an outstanding complaint that .NET doesn't let you modify the Host header a while back. It might not have been resolved. If it is really that important, you could always write socket-level code to send a prepared request (since it's just text).