【发布时间】:2016-07-04 12:35:34
【问题描述】:
我有一个 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 = 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?
【问题讨论】:
-
“管理cookies”是什么意思?一般来说,我会说
AllowAutoRedirect应该做防止自动重定向的工作,我不太明白为什么它不起作用。 -
AllowAutoRedirect 在 Windows Phone 8.1 中不可用,这就是问题
标签: c# http cookies windows-phone-8.1