Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: link to post hidden fields

by tomfahle (Priest)
on Dec 22, 2005 at 18:08 UTC ( #518598=note: print w/replies, xml ) Need Help??


in reply to link to post hidden fields

As mentioned before:
There are the LWP::UserAgent and HTTP::Request modules, which together allow you to make POST requests.
Example:
use strict; use HTTP::Request::Common qw(POST); my $url = 'http://www.somewhere.com/cgi-bin/formular.cgi'; my $req = POST $url, [ Host => 'myHost', Server => 'Any Value', OtherField => 'Some Value', OneMoreField => 'whatever', ]; # Just a debug to STDOUT print "HTTP-FullRequest-Header: \n"; print $req->headers->as_string() , "\n"; print "HTTP-FullRequest-Header-Content: \n"; print $req->content() ,"\n"; # Now send it use LWP::UserAgent; my $ua = LWP::UserAgent->new(); my $response = $ua->request($req); if ( $response->is_error() ) { print "Error-Code : ", $response->code() , "\n"; print "Error-Message : ", $response->message() , "\n"; } else { print $response->content() , "\n"; }

HTH

Replies are listed 'Best First'.
Re^2: link to post hidden fields
by js1 (Monk) on Dec 22, 2005 at 20:13 UTC

    Thanks for everyone's replies. I tried HTTP::Request::FromTemplate because that looked easiest but for some reason the request wasn't getting sent.

    The last suggestion is semi-working for me in that the request is getting sent and the browser goes to the site, but I'm not actually getting the desired page.

    I just wanted to check if I've set this up right with regards to the viewstate content below?

    my $url = 'http://lhtbod-apdhz001.uk.ad.com/ess/SignUpAsEmployee.aspx' +; my $content='__VIEWSTATE=dDwxNTk4MDgzOTc1O3Q8O2w8aTwyPjs%2BO2w8dDw7bDx +pPDE%2BOz47bDx0PDtsPGk8Mz47aTw1Pjs%2BO2w8dDxwPHA8bDxUZX h0Oz47bDxBZG1pbmlzdHJhdG9yOiA3NTIzNTk7Pj47Pjs7Pjt0PHA8cDxsPFRleHQ7Pjts +PDIyLzEyLzIwMDUgMTU6MTc7Pj47Pjs7Pjs%2BPjs%2BPjs%2BPjs%2 BBfgZ5IQIMSNKJj7%2BLszqPx1I1Co%3D&txtEmployeeID=84212&BtnSignUp=Sign+U +p'; my $req = POST $url, [ 'Host' => 'lhtbod-apdhz001.uk.ad.com', 'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; e +n-US; rv:1.8) Gecko/20051111 Firefox/1.5', 'Accept' => 'text/xml,application/xml,application/xhtml ++xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0 .5', 'Accept-Language' => 'en-us,en;q=0.5', 'Accept-Encoding' => 'gzip,deflate', 'Accept-Charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Keep-Alive' => '300', 'Connection' => 'keep-alive', 'Referer' => 'http://lhrbod-apdhz001/ess/SignUpAsEmploye +e.aspx', 'Content-Type' => 'application/x-www-form-urlencoded', 'Content-Length' => '309', 'Content' => $content, ];

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://518598]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2021-10-25 22:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (90 votes). Check out past polls.

    Notices?