|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
Hi, I read that Engine.CookieManager.SetCookies() hang if you tried to set it without url, but I not found any place where I can get cookies' url, How I can get it for set the cookies later? this method Engine.CookieManager.GetCookies() don't return urls
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
What exactly are you trying to do?
|
|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
I want to storage cookies in my properties and set them later (in the next run for example)
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Then you would just use SetCookies to add the cookie into the cookie storage. A cookie is always associated to a site (domain and Url). For example, a cookie associated to http://www.google.com would not be sent to http://www.yahoo.com. So when you call SetCookies, you MUST clearly specify the domain and the Url of the cookie. Usually you only set the domain and set the Url to the root of the site (set it to "/"). You can either set both directly on the Cookie object, or you can pass a url value when you call SetCookies. That way the Cookie's Domain and Url value will automatically derives from the url argument.
|
|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
but https://www.essentialobjects.com/doc/eo.webengine.cookiemanager.setcookie.aspx ask for a url, that I don't have I got all cookies by calling GetCookies and saved them, now I'm trying to Set them, but I don't not which url I should use, because if I call SetCookie("", cookie) it's just hang. for example this code
Code: C#
private void Form1_Load(object sender, EventArgs e)
{
webView.Create(this.Handle);
webView.LoadUrlAndWait("https://google.com"); // I loaded some url (for the example only I use google)
}
private void button1_Click(object sender, EventArgs e)
{
var allCookies = webView.Engine.CookieManager.GetCookies(); // I get all cookies
webView.Engine.CookieManager.DeleteCookies();
for (var i = 0; i < allCookies.Count; i++)
{
// now I want to set them, but I have no field with url after calling getCookies
webView.Engine.CookieManager.SetCookie(null, allCookies[i]); // I tried with null, "/" or "", one result is hang
}
allCookies = webView.Engine.CookieManager.GetCookies();
}
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Hi, You can create an Url based on the Cookie's Domain and Path. It will be something like this:
Code: C#
var cookie = allCookies[i];
string url = string.Format("{0}://www{1}{2}", cookie.Secure ? "https" : "http", cookie.Domain, cookie.Path);
webView.Engine.CookieManager.SetCookie(url, cookie);
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
well, yes, I guess there's no other ways, thanks.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
Hi, This is just to let you know that we have posted a new build that added an overloaded version of SetCookie that does not require the url argument: https://www.essentialobjects.com/doc/eo.webengine.cookiemanager.setcookie_overload_2.aspxYou can download it from our download page. Please take a look and let us know how it goes. Thanks!
|
|