C# 关闭HttpWebRequest中的自动重定向
我有一个POST请求,返回代码302C# 关闭HttpWebRequest中的自动重定向,c#,http,cookies,windows-phone-8.1,C#,Http,Cookies,Windows Phone 8.1,我有一个POST请求,返回代码302 string FormParams = "Some_string"; byte[] SomeBytes = Encoding.UTF8.GetBytes(FormParams); HttpWebRequest AuthPost = (HttpWebRequest)WebRequest.Create("https://example.com/"); AuthPost.Method = "POST"; AuthPost.AllowAutoRedirect =
string FormParams = "Some_string";
byte[] SomeBytes = Encoding.UTF8.GetBytes(FormParams);
HttpWebRequest AuthPost = (HttpWebRequest)WebRequest.Create("https://example.com/");
AuthPost.Method = "POST";
AuthPost.AllowAutoRedirect = false;
AuthPost.Accept = "text/html, application/xhtml+xml, */*";
AuthPost.Headers["Referer"] = "https://example.com/";
AuthPost.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; ASU2JS; rv:11.0) like Gecko";
AuthPost.ContentType = "application/x-www-form-urlencoded";
AuthPost.Headers["Accept-Encoding"] = "gzip, deflate";
AuthPost.Headers["DNT"] = "1";
AuthPost.Headers["Connection"] = "Keep-Alive";
AuthPost.Headers["Cookie"] = savedcookie;
AuthPost.Headers["Content-Length"] = SomeBytes.Length.ToString();
AuthPost.Headers["Cache-Control"] = "no-cache";
Stream postStream = await AuthPost.GetRequestStreamAsync();
postStream.Write(SomeBytes, 0, SomeBytes.Length);
postStream.Flush();
HttpWebResponse AuthPostResponse = (HttpWebResponse)await AuthPost.GetResponseAsync();
所以我需要在重定向之前管理返回的cookie。
如何关闭自动重定向或管理Cookie?使用CookieContainer属性/类。看
您可以在其他请求中重用容器。使用CookieContainer属性/类。看
您可以在其他请求中重用容器。您所说的“管理cookie”是什么意思?一般来说,我会说,
AllowAutoRedirect
应该起到防止自动重定向的作用,我不太明白为什么它不起作用。AllowAutoRedirect在Windows Phone 8.1中不可用,这就是问题所在“管理Cookie”是什么意思?一般来说,我会说,AllowAutoRedirect
应该起到防止自动重定向的作用,我不太明白为什么它不起作用。AllowAutoRedirect在Windows Phone 8.1中不可用这就是问题所在
CookieContainer cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;