0

ok i might be dumb cause im the only one asking this kind of question since i saw no similar questions but excuse me for that :|. quarantine just keep making me tryna learn more programming languages, got nothin to do. sorry if i kept asking for solutons everytime. cause i've tried researching for it and got nothing.

Anyway, so I tried to retrieve Cookies from a Shopping webpage with System.Net.Http; which supposed to be having the csrftoken in the Browser cookies. I tried using Python before but I got no cookies retrieved, but for some reason with C#, I got some retrieved. However, I didn't recieve the csrftoken cookie. I think it's because the cookie was based on browser session? :/. I've seen this guy getting his csrftoken, but reading the code is a bit confusing for me. How do I retrieve the csrftoken session cookie?.

This is the code that I'm currently using anyway.

            try
        {
            CookieContainer container = new CookieContainer();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://shopee.co.id/");
            request.Proxy = null;
            request.CookieContainer = container;
            request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36";
            request.Referer = "https://shopee.co.id";
            request.Headers.Add("authority", "shopee.co.id");
            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                foreach (Cookie cookie in response.Cookies)
                {
                    Console.WriteLine("Name =" + cookie.Name);
                    Console.WriteLine("Value =" + cookie.Value);
                    Console.WriteLine("Path =" + cookie.Path);
                    Console.WriteLine("Domain =" + cookie.Domain);
                }
            }
        }
Authorized
  • 53
  • 2
  • 7
  • Are you getting any exceptions or responses? If response do what is the statues? You may not be completing the connection. The code is using HTTPS (secure) which uses TLS for authentication. You have to use TLS 1.2 or 1.3 (1.0 and 1.1 have been disabled on servers). So usually the solution is to add following before the request : ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; – jdweng Dec 27 '20 at 21:59
  • I put the ServicePointManager code before the request, but it's just still the same. I do get OK responses which was the cookies I request. [This is the image of the cookies I'm getting.](https://media.discordapp.net/attachments/776982225375199252/792991862951510016/unknown.png?width=711&height=754) – Authorized Dec 28 '20 at 05:47

0 Answers0