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

I am trying to understand the HTTP::Request::Common module and manual, but the following part really has me stumped:

"A header key called 'Content' is special and when seen the value will initialize the content part of the request instead of setting a header."

It sounds like that means a place to specify the destination of the content, but it doesn't seem to work that way. Can somebdy explain it? Thanks.

Replies are listed 'Best First'.
Re: man HTTP::Request::Common
by Aristotle (Chancellor) on Jul 03, 2002 at 14:57 UTC

    It sets the body of the request. That has nothing to do with the "destination". Nominally, only POST and PUT requests may (and should) have a body so in practice, you don't use Content on GET requests.

    You really have a HTTP- and not Perl question, so you may want to read up on the protocol to understand what's going on there. Otherwise, tell us what you want to do and we'll provide the pointers you need to reach a solution.

    Makeshifts last the longest.

      Don't know if you saw this, so I will send it again (I replied to the top level instead of to your message).

      Right now, I just want the easiest way to download specific URLs to files.

      It seems that a lot of (related) packages exist:
      HTTP::Request
      HTTP::Request::Common
      HTTP::Response
      LWP::Simple
      LWP::UserAgent
      and even Net::HTTP

      I know that "more than one way exists to do it, but some explanation of the differences could help me choose the best way (for me). Thanks again.

        Actually, they are not all the same thing - they supplement each other like gearwheels. The full process is that you set up a HTTP::Request, which sent to the server via the Net::HTTP module by a LWP::UserAgent object which then constructs a HTTP::Response.

        The HTTP::Request::Common module is simply a convenience tool that provides shortcuts to common tasks in setting up HTTP::Requests.

        Likewise, the LWP::Simple module is a library that provides shortcuts to common web-related tasks. As long as you don't need finegrained control over the process, it takes care of the entire mumbojumbo of setting up a UserAgent, a Request to pass to it, and pulling the data back out of the Response and reduces it to something as simple as $page = get("http://foo.com/bar.html");.

        In your case, the gestore function does exactly what you want, as a look into the module's documentation would reveal.

        In general, if you have a task and don't know which module to look at first, the best idea is probably to look at whatever is called ::Simple* or ::Easy*.

        Makeshifts last the longest.

Re: man HTTP::Request::Common
by RMGir (Prior) on Jul 03, 2002 at 14:30 UTC
    I would guess it sets the content of the GET request (that's the section of the perldoc page that shows up in) but as far as I know, the content of GET requests is rarely used... I could be wrong. :)

    The content would be a lot more important for POST requests than GETs, I think. See the example about "Sending my ~/.profile" farther down the manpage.
    --
    Mike

Re: man HTTP::Request::Common
by Anonymous Monk on Jul 03, 2002 at 16:01 UTC
    Right now, I just want the easiest way to download specific URLs to files.

    It seems that a lot of (related) packages exist:
    HTTP::Request
    HTTP::Request::Common
    HTTP::Response
    LWP::Simple
    LWP::UserAgent
    and even Net::HTTP

    I know that "more than one way exists to do it, but some explanation of the differences could help me choose the best way (for me). Thanks again.

Re: man HTTP::Request::Common
by dwatson06 (Friar) on Jul 03, 2002 at 17:07 UTC
    I had this problem also. If the server that you are sending a POST or GET require the request to be in a specific format. You have two choices. Go into the scripts you are calling and modify the output or use Net::HTTP (or Net::SSL for encryption). When you are calling content from HTTP::Request::Common, it inserts it as content=data unless you wrap the content in brackets.
    There are some examples at the bottom of the modules along with documentation.
    Hope this helps.
Re: man HTTP::Request::Common
by gnangia (Scribe) on Nov 19, 2002 at 20:51 UTC
    I think if you are trying to submit a form with method GET, the Content is where the form entries need to be specified. I am myself struggling to get that to work. I have posted a question on the Perl Monks also. See http://www.perlmonks.org/index.pl?node_id=214016