Re: Trouble getting site
Christoph Wernli (cw@dwc.ch)
Thu, 22 Mar 2001 12:39:01 +0100
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