www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - CURL to get/set cookies

reply "Benjamin" <bhoudeshell sent.com> writes:
Hello!

I’m having issues with setting a cookie via CURL(std.net.curl).  
I’ve tried several time over the last week but can’t figure it 
out.  I feel like I've tried every suggestion I found searching 
the web.

Basically - I receive the value "set-cookie" from a GET request 
(got this), but have no idea how to feed this into next POST 
request.

Can someone point me in the right direction or provide a snippet 
of code that I could work from?

Thank you!

Benjamin Houdeshell
Apr 01 2015
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
There's two ways, you can let curl handle it by setting a cookie 
jar file:

http://dlang.org/phobos/std_net_curl.html#setCookieJar

Make the HTTP object and set the jar on it before doing any 
requests. Then it will be done automatically on that object, 
saving to the file.

If you are manually reading the Set-Cookie header, you can also 
just use this method:

http://dlang.org/phobos/std_net_curl.html#setCookie
Apr 01 2015
parent reply "Benjamin" <bhoudeshell sent.com> writes:
I"m still not able to set the cookie. Would it be possible to 
provide a few sample lines - to ensure I'm on the right path.  I 
appreciate any additional help!!

Thanks!  Benjamin


On Wednesday, 1 April 2015 at 14:33:55 UTC, Adam D. Ruppe wrote:
 There's two ways, you can let curl handle it by setting a 
 cookie jar file:

 http://dlang.org/phobos/std_net_curl.html#setCookieJar

 Make the HTTP object and set the jar on it before doing any 
 requests. Then it will be done automatically on that object, 
 saving to the file.

 If you are manually reading the Set-Cookie header, you can also 
 just use this method:

 http://dlang.org/phobos/std_net_curl.html#setCookie
Apr 05 2015
parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Sunday, 5 April 2015 at 23:55:15 UTC, Benjamin wrote:
 I"m still not able to set the cookie. Would it be possible to 
 provide a few sample lines - to ensure I'm on the right path.  
 I appreciate any additional help!!

 Thanks!  Benjamin
This should work: auto cookiesFile = "cookies.txt"; auto http = HTTP(); http.handle.set(CurlOption.cookiefile, cookiesFile); http.handle.set(CurlOption.cookiejar , cookiesFile); get("www.example.com/login.php?username=benjamin&password=hunter2", http); get("www.example.com/action.php?...", http);
Apr 05 2015
parent "Benjamin" <bhoudeshell sent.com> writes:
Vladimir & Adam Thank you!  This was my last roadblock I needed 
to overcome to finish my prototype project for the company I work 
for.  After a successful presentation and demo - the company I 
work for is taking a serious look into the D language for future 
projects.

Thanks!  Ben.


On Monday, 6 April 2015 at 04:36:36 UTC, Vladimir Panteleev wrote:
 On Sunday, 5 April 2015 at 23:55:15 UTC, Benjamin wrote:
 I"m still not able to set the cookie. Would it be possible to 
 provide a few sample lines - to ensure I'm on the right path.  
 I appreciate any additional help!!

 Thanks!  Benjamin
This should work: auto cookiesFile = "cookies.txt"; auto http = HTTP(); http.handle.set(CurlOption.cookiefile, cookiesFile); http.handle.set(CurlOption.cookiejar , cookiesFile); get("www.example.com/login.php?username=benjamin&password=hunter2", http); get("www.example.com/action.php?...", http);
Apr 16 2015