Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

How can I send a cookie as part of an HTTP request?

( #46680=categorized question: print w/ replies, xml ) Need Help??
Contributed by Anonymous Monk on Dec 14, 2000 at 23:32 UTC
Q&A  > HTTP and FTP clients


Description:

I'd like to use get($url) to retrieve the contents of a web page, but I need to have a cookie set in order for the request to work. Is there a function similar to get() which allows a cookie to be set in the header of the URL before the call?

Thank you!
MB

mtblank@mindless.com

Answer: How can I send a cookie as part of an HTTP request?
contributed by chipmunk

The LWP package includes modules for handling cookies, but they're not documented in LWP or lwpcook. Instead, you have to look at HTTP::Cookies and LWP::UserAgent.

Answer: How can I send a cookie as part of an HTTP request?
contributed by kilinrax

Assuming you mean the header of a HTTP request, have a look at HTTP::Header

Answer: How can I send a cookie as part of an HTTP request?
contributed by cei

Keep in mind that you can only set cookies for your own domain. If your get($url) is pulling from someone else's machine, and you're wanting to pre-login to that machine by making a cookie for it, it won't work. On the other hand, if you want to use the cookie to keep track of where someone is on your site before pulling contents from another site, that should work fine.

I use CGI.pm for my cookie handling.

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (6)
    As of 2014-12-18 01:20 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (41 votes), past polls