Cookies do not work in HttpWebRequest .net c# request for some unknown reason

109 views Asked by At

I don't speak English very well, sorry in advance for any grammatical errors.

  1. I have my own 3128 lines of cookies.
  2. They are in netscape format.
  3. I want to go into Gmail.

The thing is, I can't log in, every time I get a reply page with the login to my Gmail account.

I thought the cookies were too big, so I deleted 300 and was able to log in. The reply page came back with my Gmail and my name. From the beginning, I wasn't sure if it was because of the size of the cookies. I tried gradually deleting cookie lines from 300 to 0, then 260 to 0, and so on and so forth. After deleting from 254 cookies, my Gmail login stopped working.

That is, the last line under the domain: .just-wiped.net - as if it wouldn't let me through. (number 255).

I left it as it is, deleting all the 254 cookies, and my Gmail login doesn't work again. But if I delete or change the line under number 255 (.just-wiped.net)-the login works. But it works if more than 249 cookies are deleted. And if only line number 255 is deleted and the rest are not deleted, then the login also does not work. What is the reason I don't understand. I hope I am clear, let me know what I should correct if you don't understand.

The code is how I make the request with 3000+ cookies.

    //Adding cookies to a container
    public static List<String[]> GetCookieLines(String fileName)
    {
        List<String[]> cookieLines = new List<String[]>();
        using (FileStream fs = new FileStream(fileName, FileMode.Open))
        using (StreamReader rdr = new StreamReader(fs, Encoding.UTF8))
        {

            String line;
            while ((line = rdr.ReadLine()) != null)
            {
                String[] components = line.Split('\t');
                cookieLines.Add(components);
            }
        }
        return cookieLines;
    }

static void Main(string[] args) {
        CookieContainer cookieContainer = new CookieContainer();
        Console.WriteLine("File path");
        string d = Console.ReadLine();

        List<String[]> list = new List<string[]>();

        list = GetCookieLines(d); //Adding a cookie to a new list

        //Adding netscape cookies to cookieContainer
        foreach (string[] p in list)
        {
            cookieContainer.Add(new Cookie(p[5].Replace(",", "%2C"), p[6].Replace(",", "%2C"), "/", p[0].Replace(",", "%2C")));
        }

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://mail.google.com/mail/u/0/#inbox");
        request.CookieContainer = cookieContainer;
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        using (Stream stream = response.GetResponseStream())
        {
            using (StreamReader reader = new StreamReader(stream))
            {
                string line = "";
                while ((line = reader.ReadLine()) != null)
                {
                    Console.WriteLine(line);
                }
            }
        }

        Console.ReadKey();
    }

Here's a view of the cookie: enter image description here

Please help me. I spent 2 days figuring out why the input does not work, then I realized that it is a problem with cookies, but I can not go any further.

Please advise what could be the problem, what to look for in cookies, maybe another way to load them, maybe cookies themselves interfere, or some errors.

UPD: Cookies turn out not to work only because of the string with the domain : .just-wiped.net.

If you delete 300 cookies, then the authorization works. There are a few wrong lines, but why it happens and what lines I have no idea. Maybe I download the cookies wrong or maybe I don't convert netscape correctly. In my browser everything works though.

0

There are 0 answers