Pass Multiple Cookie Name Value Pairs in GlobalCookiemanager

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Pass Multiple Cookie Name Value Pairs in GlobalCookiemanager

Postby vish92 » Sun Apr 09, 2017 6:22 am

Hi,

I am using Cef to scrape a website and fetch one of the div element from its Data Object Model. The issue is that, that website needs a username and password to login. I am using GetGlobalCookiemanager.SetcookieAsync to pass the cookie. In the Cookie object, it is mentioned that it accepts" name: value pair". But my cookie has multiple name value pairs. Is there any way through which i can pass multiple name value pairs that are present in my cookie to bypass the login page? Please let me know if I am missing something?
vish92
Newbie
 
Posts: 3
Joined: Sun Apr 09, 2017 5:52 am

Re: Pass Multiple Cookie Name Value Pairs in GlobalCookieman

Postby HarmlessDave » Sun Apr 09, 2017 3:09 pm

A single cookie has only one name and one value. The value can be anything including a list of things like (name) = access, (value) = user:fred;password:apple;timeset:20170408-001536

To set 2 cookies, just call set cookie twice.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Pass Multiple Cookie Name Value Pairs in GlobalCookieman

Postby vish92 » Mon Apr 10, 2017 4:55 am

Thanks for your reply!! That implies that I will call SetCookieAsync multiple times to set multiple cookies. Please correct me if am wrong. To visit all those cookies, do I have to use any of the below :
- VisitAllCookies
-VisitAllCookiesAsync()
if yes, how do I utilize the above in my code? I could not find any on blogs.
vish92
Newbie
 
Posts: 3
Joined: Sun Apr 09, 2017 5:52 am

Re: Pass Multiple Cookie Name Value Pairs in GlobalCookieman

Postby HarmlessDave » Mon Apr 10, 2017 11:26 am

Are you using CEF or something else like the C#, Java, Delphi bindings?

In CEF3 we create a CefCookieVisitor (or subclass of it) object, get the cookie manager, then pass the CookieVisitor to VisitUrlCookies like this:

Code: Select all
CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager(NULL);
if (manager != NULL)
{
    manager->VisitUrlCookies(szURL, true, new MyCookieVisitorAsync(browser));
}


See also: viewtopic.php?f=14&t=13915
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: Pass Multiple Cookie Name Value Pairs in GlobalCookieman

Postby vish92 » Tue Apr 11, 2017 1:59 am

Hi,

I am using CEF for this. Can you please explain a little more on the usage of VisitAllCookies and VisitAllCookiesAsync ? Which one can I use for utilizing all my cookies? Also, can you please clear on what should be the implementation of Visitor if VisitAllCookies has to be used?
vish92
Newbie
 
Posts: 3
Joined: Sun Apr 09, 2017 5:52 am

Re: Pass Multiple Cookie Name Value Pairs in GlobalCookieman

Postby HarmlessDave » Tue Apr 11, 2017 11:33 am

What version of CEF are you using? CEF3 only has VisitAll and VisitURL, both of them are asynch:
Code: Select all
http://magpcss.org/ceforum/apidocs3/projects/(default)/CefCookieManager.html
http://magpcss.org/ceforum/apidocs3/projects/(default)/CefCookieVisitor.html


All returns cookies for every subdomain. URL returns cookies for a specific site.

You create a subclass of CefCookieVisitor like MyCookieVisitor and pass that to the cookie manager. It has a Visit function that will be called once per cookie. That Visit function can do something with the cookie, or set flags or cache the cookie data into a pair of string lists or whatever.

After cookie manager has sent all cookies to the Visit function, the destructor for your MyCookieVisitor object is called. At that point you can again do whatever you want -- search the cookie data if you built string lists, look at flags that you set, set cookies, etc.

Edit: just to be clear, you only need to do this to read cookies. To set cookies you just get the cookie manager and then call SetCookie once per cookie = name-value pair.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 31 guests