C#WebClient标头的排序不相同

C#WebClient标头的排序不相同,c#,http-headers,http-post,webclient,C#,Http Headers,Http Post,Webclient,守则: using (WebClient wc = new WebClient()) { if (Form1.ProxyEnabled) { WebProxy wp = new WebProxy(string.Format("{0}:{1}", PAddress, PPort)); if (Form1.AuthenRequired

守则:

using (WebClient wc = new WebClient())
            {
                if (Form1.ProxyEnabled)
                {
                    WebProxy wp = new WebProxy(string.Format("{0}:{1}", PAddress, PPort));
                    if (Form1.AuthenRequired)
                        wp.Credentials = new NetworkCredential(PUser, PPass);
                    wc.Proxy = wp;
                }
                ServicePointManager.Expect100Continue = false;

                wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                wc.Headers[HttpRequestHeader.Referer] = "xxxxxxxxxxxxxx";
                wc.Headers[HttpRequestHeader.UserAgent] = ua;
                wc.Headers[HttpRequestHeader.AcceptLanguage] = "en-US,en;q=0.8";
                wc.Headers[HttpRequestHeader.Accept] = "*/*";
                wc.Headers.Add("Custom", "xxxxxxxxxxxxxx");

                Uri URI = new Uri("xxxxxxxxxxxxxx");
                ResultString = wc.UploadString(URI, ss);
            }
结果是:

POST /api.php HTTP/1.1
Accept-Language: en-US,en;q=0.8
Custom: xxxxxxxxxxxxxx
Accept: */*
Content-Type: application/x-www-form-urlencoded
Referer: xxxxxxxxxxxxxx
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11
Host: xxxxxxxxxxxxxx
Content-Length: xxxxxxxxxxxxxx
Connection: Keep-Alive
POST /api.php HTTP/1.1
    Host: xxxxxxxxxxxxxx
    Content-Type: application/x-www-form-urlencoded
    Referer: xxxxxxxxxxxxxx
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11
    Accept-Language: en-US,en;q=0.8
    Accept: */*
    Custom: xxxxxxxxxxxxxx
    Content-Length: xxxxxxxxxxxxxx
    Connection: Keep-Alive
预期结果是:

POST /api.php HTTP/1.1
Accept-Language: en-US,en;q=0.8
Custom: xxxxxxxxxxxxxx
Accept: */*
Content-Type: application/x-www-form-urlencoded
Referer: xxxxxxxxxxxxxx
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11
Host: xxxxxxxxxxxxxx
Content-Length: xxxxxxxxxxxxxx
Connection: Keep-Alive
POST /api.php HTTP/1.1
    Host: xxxxxxxxxxxxxx
    Content-Type: application/x-www-form-urlencoded
    Referer: xxxxxxxxxxxxxx
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11
    Accept-Language: en-US,en;q=0.8
    Accept: */*
    Custom: xxxxxxxxxxxxxx
    Content-Length: xxxxxxxxxxxxxx
    Connection: Keep-Alive

那么,发生了什么?为什么标题的顺序与我添加标题的顺序不一样,以及如何解决这个问题?如何按照准确的顺序发送自定义标题?

我使用了tcpclient,一切都很好。

顺序应该不会有什么不同。你为什么关心顺序不同?我知道没有区别,它确实起到了应有的作用,但我想以相同的顺序进行,原因有二:1。它必须100%模拟请求2。我只想知道发生了什么事!您必须了解,如果订单没有影响,那么您100%模拟了请求。就这么简单。类库设置顺序。您可以启用属性并设置值,但无法控制它们的发送顺序。如果你真的想更改顺序,你需要使用不同的库。但另一端可以检查,并知道这只是一个虚假的请求,而不是来自浏览器的真实请求。我错了吗?我想我会选择TcpClient。