develooper Front page | perl.libwww | Postings from March 2001

Re: Trouble getting site

Thread Previous
From:
Christoph Wernli
Date:
March 22, 2001 03:37
Subject:
Re: Trouble getting site
Message ID:
3AB9E455.43FC43BE@dwc.ch
John W Cunningham wrote:
> 
> I'm having trouble pulling a certain site.  Ordinarily this script works
> perfectly, but it just doesn't want to retrieve this site.  What am I doing
> wrong?

There are actually three problems:

> print &WWWget("http://registrar.ucdavis.edu/CSRD/spring2001/(AAS).html");
> 
> sub WWWget {
> 
>                 # Create a user agent object
>                 use LWP::UserAgent;
>                 $ua = new LWP::UserAgent;
>                 $ua->agent("Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt" .
> $ua->agent);

2nd problem: This server doesn't like your UserAgent. Just leave out setting the agent
name altogether (which is probably a nice thing anyway).

>                 #Timeout
>                 my $timeout = 10000;
> 
>                 # Create a request
>                 my $req = new HTTP::Request GET => $_[0];
>                 $req->content_type('application/x-www-form-urlencoded');
>                 $req->content('match=www&errors=0');

1st problem: Setting content_type and content is usefull only for POST requests.

>                 # Pass request to the user agent and get a response back
>                 my $res = $ua->request($req);
> 
>                 # Check the outcome of the response
>                 if ($res->is_success) {
> 
>                         return($res->content);
> 
>                         print(".");
>                 }else{
>                         print("Mine Error - ",$_[0],"\n");

3rd problem: this line should read:

print $res->error_as_HTML;

>                 }
> }

Hope this helps,

-Christoph

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About