Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting result of another web page using perl

Status
Not open for further replies.

Tirumaran

IS-IT--Management
Oct 30, 2000
5
MY
Hi,

I am trying to get a content of a web page using http inside a perl program.
for eg. if i pass a url address for e.g.
" the script should fetch the result
page and output return should be the text content of the page.

I am trying to call another script located in another machine, and that script suppose to update the database using
the variable that i passed.

I tried using LWP module , downloaded from CPAN, but still can;t get the result. below is the code that i tried. Please
help.
Thank You.
Regards,
Tirumaran M
tiru@tmm.com.my


---------------------------------------------------------------------------------------------------
#!/perl/bin/perl

# Create a user agent object
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$ua->agent("AgentName/0.1 " . $ua->agent);

# Create a request
my $req = new HTTP::Request POST => ' $req->content_type('application/x- $req->content('cmd=view&id=784');


# Pass request to the user agent and get a response back
my $res = $ua->request($req);
print "before";
print $res->content;
print "after";
# Check the outcome of the response
if ($res->is_success) {
print $res->content;
} else {
print "no content fetched\n";}
 
Using LWP::Simple, rather than UserAgent.

Code:
#!/usr/local/bin/perl
use LWP::Simple;
unless ($url = @ARGV[0]) die "No url specified"; }
$content = get($url);
print "$content";

Works just fine on the URL above.

'hope this helps.....




keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top