奇怪的内容类型重定向HttpWebRequest C#

本文关键字:重定向 HttpWebRequest 类型 | 更新日期: 2023-09-27 18:02:44

代码:

webRequest = WebRequest.Create("https://---.com/bbb.aspx") as HttpWebRequest;
            webRequest.Method = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.CookieContainer = cookies;
            webRequest.KeepAlive = true;
            webRequest.Proxy = new WebProxy("127.0.0.1:8888");
            webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36";
            webRequest.Referer = "https://---.com/bbb.aspx";
            webRequest.MaximumAutomaticRedirections = 1;
            webRequest.AllowAutoRedirect = true;
            webRequest.ServicePoint.SetTcpKeepAlive(true, 15, 200);
            webRequest.ServicePoint.UseNagleAlgorithm = false;
            webRequest.ServicePoint.Expect100Continue = false;

它被重定向到ccc.aspx。http头(Fiddler(是

POST https://---.com/bbb.aspx HTTP/1.1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko)       Chrome/34.0.1847.116 Safari/537.36
Referer: https://---.com/bbb.aspx
Host: ---.com
Cookie: ASP.NET_SessionId=************; skysales=**********
Content-Length: 1753

直接到ccc.aspx是成功的,但为什么内容类型头也是application/x-wwww-form-urlencoded,在fiddler中,它是GET请求,而不是POST

GET https://---.com/ccc.aspx HTTP/1.1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko)    Chrome/34.0.1847.116 Safari/537.36
Host: ---.com
Cookie: ASP.NET_SessionId=*********; skysales=********

奇怪的内容类型重定向HttpWebRequest C#

这是HttpWebRequest中的一个错误,在这行代码中。

在处理重定向响应时,它们会正确地重置方法,但不会删除相关的标头。