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

Hi,

Im familiar with both WWW::Mechanize, LWP and all the other web request libs. But I need to make webrequest, where I can define all the headers. So is there a way I can make a perl script send a request like this:

POST http://google.no/ HTTP/1.1 Host: google.no User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1 +4) Gecko/2009082707 Firefox/3.0.14 (.NET CLR 3.5.30729) Paros/3.2.13 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0. +8 Accept-Language: en-us,en;q=0.5 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Proxy-Connection: keep-alive Cookie: PREF=ID=067cb3c498f1ba5a:U POST_DATA_HERE

The aim is to be able to set and craft the request in its entirety, and get the response back from the server

Replies are listed 'Best First'.
Re: Craft http request?
by arkturuz (Curate) on Sep 25, 2009 at 10:02 UTC
    Use LWP::UserAgent with HTTP::Request like this:
    my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new( POST => $my_uri ); $req->header("Header 1", "Value 1"); $req->header("Header 2", "Value 2"); # etc
      Cool. Is PUT, TRACE etc also supported? or is it only POST and GET?
        I believe no. But check the documentation anyway.