Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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


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!

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 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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

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

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (5)
    As of 2016-08-25 08:31 GMT
    Find Nodes?
      Voting Booth?
      The best thing I ever won in a lottery was:

      Results (354 votes). Check out past polls.