0

So I was using FIddler, trying to look through how I could create a HttpWebRequest to login to Spotify.com Then I realized I needed the cookies it provies when logging in. Here is a picture showing the cookies

Issue is that I cant seem to store any cookies using a cookie container, mine is just empty. How do I get the __bon _ga _gat and _gid cookies and store them in a cookiecontainer?

    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();
Aleks Slade
  • 211
  • 1
  • 2
  • 11
  • Most of those cookies are from Google Analytics. If you want them in your cookiecontainer you need to execute the javascript that sits in that page. That probably sets of other http calls that you need to implement as well. The same can be true for the other cookies. – rene Dec 20 '17 at 20:14
  • So.. How do I execute that javascript with C#? @rene – Aleks Slade Dec 20 '17 at 20:37
  • Use a browser? There is a lousy one in .Net called WebBrowser, alternative is Chromium. Or you observe what the script is doing / calling and then mimic that. Keep in mind that some sites don't like it to be scraped so they have all kind of countermeasures to prevent anyone from succeeding. You have to outsmart them. Here is [an example](https://stackoverflow.com/a/24590419/578411) where I scrape a site that has some trickery. You'll need to build something similar, reverse engineering spotify's http calls. – rene Dec 20 '17 at 21:00
  • Ahh alright! Thanks for the information. – Aleks Slade Dec 20 '17 at 21:05

0 Answers0