Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

print Location

Posted on 2000-04-12
6
Medium Priority
?
155 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
ID: 2709249
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
ID: 2709322
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 200 total points
ID: 2709452
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:flahertd
ID: 2712198
Adjusted points from 25 to 50
0
 

Author Comment

by:flahertd
ID: 2712199
thanks for your help maneshr!
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2712242
most welcome:-)

Glad to know that the script worked for you.

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

783 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