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

Hi! I would really appreciate if somebody could please help me. I am using HTTP::Request:Common to perform a "GET" on a form? How would I do it? If this is not the right module for my request, please let me know that also!
Thanks
  • Comment on Using HTTP::Request::Common to do a GET with form-data?

Replies are listed 'Best First'.
Re: Using HTTP::Request::Common to do a GET with form-data?
by Enlil (Parson) on Nov 19, 2002 at 02:57 UTC
Re: Using HTTP::Request::Common to do a GET with form-data?
by pg (Canon) on Nov 19, 2002 at 04:12 UTC
    Yes, HTTP::Request, HTTP::Request::Common, HTTP::Headers are the right modules for forming the 'POST' request. You also need something to send this request to the server, LWP::UserAgent is one of many modules you can use.
      Just to let you know, forms have something called "method" which could be a "post" or "get". The primary difference between th two is mostly for security. When the method is "get", and the submit button is clicked, then the url shows all the parameters of the form in clear text as part of the url. However, in a "post", it does not show, so one would mostly use this method for transmitting passwords which when submitted, does not show up as part of the url.
      Thanks for the advice, but I have been pulling my hair apart to get the GET with form paramters working.
Re: Using HTTP::Request::Common to do a GET with form-data?
by Wonko the sane (Curate) on Nov 19, 2002 at 03:49 UTC
    Depending on your needs you may be able to use LWP::Simple.
    Makes posting to a form very easy.

    perl -MLWP::Simple -ne 'getprint("http://your_site.com/form.cgi?unsubs +cribe=1&who=me" )'

    Note though that any form variables that you want to submit to the form will have to be properly encoded.

    Modules like URI::Escape can help with that though. :-)

    Hope that helps.

    Wonko

Re: Using HTTP::Request::Common to do a GET with form-data?
by gnangia (Scribe) on Nov 19, 2002 at 16:45 UTC
    Wonko the sane : - I tried your command against google's website but does not work. Here is the command I used -
    perl -MLWP::Simple -ne 'getprint("http://www.google.com /search?hl=en&ie=UTF-8&oe=UTF8&q=test")'
    . The response was 403 Forbidden. What's wrong with this query ?
      I tried your command against google's website ...
      ...The response was 403 Forbidden. What's wrong with this query ?

      Whats wrong is the google doesn't like the LWP User Agent and will always return 403 to any request with the LWP UA. See this email thread (which I found from a google search). You need to set the UA to something like 'Mozilla/3.142', which I don't believe is possible using LSP::Simple. See doco on LWP and LWP::UserAgent

      Dingus


      Enter any 47-digit prime number to continue.
      I tried your command against google's website ...
      ...The response was 403 Forbidden. What's wrong with this query ?

      Whats wrong is the google doesn't like the LWP User Agent and will always return 403 to any request with the LWP UA. See this email thread (which I found from a google search). You need to set the UA to something like 'Mozilla/3.142', which I don't believe is possible using LWP::Simple. See doco on LWP and LWP::UserAgent

      Dingus


      Enter any 47-digit prime number to continue.
        Dingus => I was just using google.com as an example of my test. I am trying to locate any sample script that uses method GET for submitting a form using the HTTP::Request::Common method.
        Thanks