C# WebClient Headers 不属于同一类
C# WebClient Headers not in the same sort
代码:
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
所以,发生了什么事?为什么 headers 与我添加的顺序不同,如何解决?如何按准确顺序发送自定义 headers?
我使用了 tcpclient,一切正常。
代码:
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
所以,发生了什么事?为什么 headers 与我添加的顺序不同,如何解决?如何按准确顺序发送自定义 headers?
我使用了 tcpclient,一切正常。