Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Craft http request?

by perlpreben (Beadle)
on Sep 25, 2009 at 09:21 UTC ( #797429=perlquestion: print w/replies, xml ) Need Help??

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


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/1.1 Host: User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: +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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://797429]
Approved by broomduster
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2020-10-28 06:58 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (260 votes). Check out past polls.