2

When attemping to access a given URL, it tells me I have to enable cookies in my browser. How exactly do I do that in my console application? This is my code:

using System.IO;
using System.Net.Http;

namespace EmailChecker
{
    class Test
    {
        public static void TestStuff()
        {
            string url = "https://login.live.com/";
            var httpClient = new HttpClient();

            var html = httpClient.GetStringAsync(url);

            using (StreamWriter sw = new StreamWriter(@"../../../Results/testresult.html"))
            {
                sw.Write(html.Result);
            }
        }
    }
}

I have also tried manually adding every cookie I saw in my browser's Dev-tools like so:

                CookieContainer gaCookies = new CookieContainer();
                Uri target = new Uri("http://login.live.com/);
                gaCookies.Add(new Cookie("cookieName", "cookieValue") { Domain = target.Host });

Repeating the line for every cookie, each with it's respective name and value. What am I doing wrong?

neverlink
  • 21
  • 1
  • 2
  • This may solve your problem https://stackoverflow.com/questions/12373738/how-do-i-set-a-cookie-on-httpclients-httprequestmessage – Shervin Ivari Dec 15 '19 at 17:05

0 Answers0