Solved

print Location

Posted on 2000-04-12
6
147 Views
Last Modified: 2013-12-25
Can:
print "Location: http://www.where-ever.com\n\n";
be used to write the contents of a web page to a file?

As in, will:
print FILE "Location: http://www.where-ever.com\n\n";  
work??

0
Comment
Question by:flahertd
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
print "Location: http://www.where-ever.com\n\n";

only redirects you to the given web page.

Therefore print FILE "Location: http://www.where-ever.com\n\n";  
WILL NOT write the contents of that page to your file. it will only write the STRING Location: http://www.where-ever.com\n\n" to the file.

To do that you will have to use other PERL modules.

i have exactly such a PERL script with me. if you want the same, let me know & i will post it to this forum.
0
 

Author Comment

by:flahertd
Comment Utility
maneshr,

Yeah, that'd be great, if you don't mind.

I can increase the points too if you'd like!

0
 
LVL 16

Accepted Solution

by:
maneshr earned 50 total points
Comment Utility
sure. here is the script....

this script gets the required page using HTTP protocol. in fact, its a very basic version of your own browser!!!

if the script cant get the web site it shows why with the help of error message.

you might have to change the path to perl and other files as per your system.
==============get_site.pl
#!/usr/local/bin/perl

require LWP;
require URI::URL;

use strict;
use CGI;

my($hdr,$server_response);
my($statement_URL)="http://www.where-ever.com";

my($query)=new CGI;

##  Right now the values are hard-coded
$hdr="";

$server_response=&browse($statement_URL,$hdr);  ##  Fire the URL

print "Content-type: text/html\n\n";

if ($server_response){
  open(FILE,"/tmp/home_page.html") || die $!;
  print FILE $server_response;
  close(FILE);
  print "<B>Got your Website!!</b>\n";
}else{
  print "<B>Sorry! Could not get your Website!!</b><P>\n";
  print "Error is $server_response<br>\n";
}

## This is the main sub routine!!  
sub browse(){
  my($statement_URL,$hdr)=@_;
  my($content_type,$method,$url,$request,$response);
 
  $content_type="application/x-www-form-urlencoded";
  $method="GET";
 
  my($headers)= new HTTP::Headers
  'Content-Type'   =>  $content_type,
  'MIME-Version'   =>  '1.0',
  'Date'           =>  HTTP::Date::time2str(time),
  'Accept'         =>  'text/html';

  my($ua)= new LWP::UserAgent;
  $ua->agent("Mozilla/4.7 [en] (WinNT; U)"); # Define env variable - HTTP_USER_AGENT

  $url= new URI::URL($statement_URL."?".$hdr);
  $request= new HTTP::Request($method, $url, $headers);


  my($response)= $ua->request($request);

  my($reply);

  if ($response->is_success){
    $reply=$response->content;
  }else{
    $reply=$response->error_as_HTML();
  }
  return $reply;
}

================================

Hope that helps
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:flahertd
Comment Utility
Adjusted points from 25 to 50
0
 

Author Comment

by:flahertd
Comment Utility
thanks for your help maneshr!
0
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
most welcome:-)

Glad to know that the script worked for you.

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now