×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

LWP::Simple script

LWP::Simple script

LWP::Simple script

(OP)
I have a script that works OK from the command line but bombs from the web server:

#!/usr/bin/perl
use LWP::Simple;
$url = 'http://whatever/labo.asp';
$content = get($url);
print "$content";

Here is the server error_log:

httpd: [Wed Nov 15 00:11:52 2000] [error] [client xxx.xxx.xxx.xxx] malformed header from script. Bad header=<HTML><BODY>: /home/httpd/cgi-bin/script.pl

Can someone please help.
Thanks.

RE: LWP::Simple script

You need to add a 'Content-type' line to make the output compliant so the browser understands what it is getting.


#!/usr/bin/perl
use LWP::Simple;
$url = 'http://whatever/labo.asp';
$content = get($url);
print "Content-type: text/html\n\n";
print "$content";


When you print to a browser from a piece of CGI, you must provide the Content-type info.  When you use the get method to retrieve a remote page, you do not get that line with the remote page.  So, you must add it before you try to print the retrieved page back to your browser.

'hope this helps.....

 
 
 
 keep the rudder amid ship and beware the odd typo

RE: LWP::Simple script

(OP)
Thanks for your input goBoating.
So I have changed the script like you said, and now, when I access the script, I get a download dialog box. If I save the file to disk and look at it, I find it contains the output from the script, with the html and head and other tags. Why doesn't it just open in my browser???

RE: LWP::Simple script

If copied the text of the code in my previous post, changed the first line to point at my Perl, changed the 'whatever/labo.asp' to a real page, and ran it and it worked fine.  
You must have STDOUT redirected or a different file handle SELECTed, if your output is not making it to the browser.

I would suggest playing with the code above until you can make it work.  Don't put it in anything else, just get it to work by itself.   Once, your convinced it works, try to fold it into your other code.

'hope this helps....

 
 
 
 keep the rudder amid ship and beware the odd typo

RE: LWP::Simple script

(OP)
ok now it works... my mistake: I had
print "Content-type: text\html\n\n";
instead of
print "Content-type: text/html\n\n";
thanks.

RE: LWP::Simple script

Hi i am a beginner in perl. I tried to use the script you mentioned above. But i don't seem to be able to run the script. I am suspecting that i am behind the firewall. Have you any ideas of how to get around that?

RE: LWP::Simple script

hey coke,

The firewall is not my first guess for your problem.  Your firewall should allow responses to internal requests to come back into your network.  If you can reach the web with a browser from inside your fire wall, then the firewall is not your problem.  The Perl LWP::Simple module behaves just like a browser request for a web page.

Are you sure the script runs?  
While in the dir where the script is sitting, try 'perl -c scriptName', where scriptName is the name you saved it to.  That will do a syntax check on the code.

If that works, try 'perl -e scriptName SomeWebAddress'.  That should retrieve the requested HTML and blow it all over the screen (raw HTML).  

Let me know if you need more.

'hope this helps.

 
 
 
 keep the rudder amid ship and beware the odd typo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close