There is a code. I want to get cookies with webbrowser1. Writes an error:

Unhandled "System.Net.CookieException" type exception in System.dll Additional information: Invalid part "Value" = "7200.0" cookie.

What am I doing wrong???

public CookieContainer GetCookieContainer() { CookieContainer container = new CookieContainer(); foreach (string cookie in webBrowser1.Document.Cookie.Split(';')) { string name = cookie.Split('=')[0]; string value = cookie.Substring(name.Length + 1); string path = "/"; string domain = ".steamcommunity.com"; //change to your domain name container.Add(new System.Net.Cookie(name.Trim(), value.Trim(), path, domain)); } return container; } 

The cookies themselves _ga=GA1.2.1317698739.1478508335; timezoneOffset=7200,0; sessionid=15c54f90d07c675352504989; steamCountry=UA%7Cd0fdd0d7b615e7c0200338daca9e4cc4 _ga=GA1.2.1317698739.1478508335; timezoneOffset=7200,0; sessionid=15c54f90d07c675352504989; steamCountry=UA%7Cd0fdd0d7b615e7c0200338daca9e4cc4

Added value = Regex.Replace(value, ",", "."); but it doesn't plow. Although the cookie passes from the function. I did something zepsep when I fixed 7200.0 to 7200.0 ???

    1 answer 1

    Here it explains in detail why you have an exception. Quote:

    The following characters are reserved and cannot be passed to the value parameter if the string that is passed to the value parameter is enclosed in double quotes: semicolon, comma.

    Your problem is solved very simply.

     public CookieContainer GetCookieContainer() { CookieContainer container = new CookieContainer(); foreach (string cookie in webBrowser1.Document.Cookie.Split(';')) { string name = cookie.Split('=')[0]; string value = cookie.Substring(name.Length + 1); string path = "/"; string domain = ".steamcommunity.com"; //change to your domain name container.Add(new System.Net.Cookie(name.Trim(), @value.Trim(), path, domain)); } return container; }