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

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:

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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2020-01-18 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?