如何获取cookie并使用HttpWebRequest存储它们

时间:2017-12-20 20:10:51

标签: c# .net cookies httpwebrequest httpwebresponse

所以我使用的是FIddler,试图了解如何创建HttpWebRequest以登录Spotify.com 然后我意识到我需要登录时提供的cookie。 Here is a picture showing the cookies

问题是我似乎无法使用cookie容器存储任何cookie,我的只是空的。 如何获取__bon _ga _gat和_gid cookie并将它们存储在cookie容器中?

    HttpWebRequest theRequest = (HttpWebRequest)WebRequest.Create("https://accounts.spotify.com/en/login"); 
theRequest.Proxy = null; 
theRequest.Method = "GET"; 
theRequest.Accept = TheAccept;
 theRequest.UserAgent = User_Agent;
 theRequest.Headers.Add("Accept-Encoding", "gzip, deflate"); theRequest.Headers.Add("Accept-Language", "en-US,en;q=0.9"); theRequest.Headers.Add("Upgrade-Insecure-Requests", "1"); theRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; theRequest.AllowAutoRedirect = false; 

    //This right here is empty
    var container = theRequest.CookieContainer = new CookieContainer();

0 个答案:

没有答案