Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Learning/Trying to use Net::Curl with Cookie Jar

by YenForYang (Beadle)
on Feb 22, 2018 at 13:37 UTC ( [id://1209746]=perlquestion: print w/replies, xml ) Need Help??

YenForYang has asked for the wisdom of the Perl Monks concerning the following question:

I've never used libcurl before, but I wanted to start using it in curl for improved HTTP performance. I've been looking through all the Net::Curl::Easy:: keys, browsing the contents and comparing with curl.haxx.se and noticed that Net::Curl doesn't have a curl_easy_cleanup function.

I'm asking this because on the manual page for CURLOPT_COOKIEJAR, it says

...will make libcurl write all internally known cookies to the specified file when curl_easy_cleanup is called.

So...How does one store cookies in a cookie jar (file) by specifying CURLOPT_COOKIEJAR?

EDIT: To give an idea of what I'm trying to do for now (this case): I'm making a simple GET request pretty much equivalent to this: curl -qsL -b cookies.txt -c cookies.txt <URL> and parse the html response content (html of URL).

Replies are listed 'Best First'.
Re: Learning/Trying to use Net::Curl with Cookie Jar
by YenForYang (Beadle) on Feb 22, 2018 at 19:56 UTC
    I actually just found curl_easy_cleanup in this chunk of code from Curl_Easy.xsh:
    static void perl_curl_easy_delete( pTHX_ perl_curl_easy_t *easy ) /*{{{*/ { /* this may trigger a callback, * we want it while easy handle is still alive */ curl_easy_setopt( easy->handle, CURLOPT_SHARE, NULL ); /* when using multi handle, the connection may stay open in th +at multi, * but the easy will be long dead. In case of ftp for instance +, connection * closing will send a trailer with no apparent destination */ /* this also disables header callback if not using multi, SORR +Y */ curl_easy_setopt( easy->handle, CURLOPT_HEADERFUNCTION, NULL ) +; curl_easy_setopt( easy->handle, CURLOPT_WRITEHEADER, NULL ); if ( easy->handle ) curl_easy_cleanup( easy->handle ); perl_curl_easy_delete_mostly( aTHX_ easy ); if ( easy->share_sv ) sv_2mortal( easy->share_sv ); Safefree( easy ); } /*}}}*/

    Now I just have to figure out how to call it....

Re: Learning/Trying to use Net::Curl with Cookie Jar
by Anonymous Monk on Feb 22, 2018 at 14:47 UTC
    http://search.cpan.org/grep?cpanid=SYP&release=Net-Curl-0.39&string=Cook&i=1&n=1&C=0
    t/03-cookies.t 10:eval { $easy->setopt(CURLOPT_COOKIEFILE, '') }; 11:ok((not $@), 'checking if libcurl was compiled with COOKIES feature +'); lib/Net/Curl/examples.pod 360: # share cookies between all handles 362: $share->setopt( CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE ); 647:This module shows how one can share http cookies and dns cache bet +ween multiple 713: # share both cookies and dns 714: $self->setopt( CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE ); 1065: $easy->setopt( CURLOPT_COOKIEFILE, '' );
      I thought CURLOPT_COOKIEFILE was read-only:
      This option only reads cookies. To make libcurl write cookies to file, see CURLOPT_COOKIEJAR.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1209746]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 22:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found