Solved

print Location

Posted on 2000-04-12
6
151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 50 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
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

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 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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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