Jump to content

Perl, the HTTP request problem.


heero11yuy

Recommended Posts

How to run a perl file / call a perl function on a HTTP page, if possible? Is there any sample for it? It'd be very appreciated if coding is provided... thanks a lot~!I actually wrote it for to run a perl file on its own server, but when I run it on HTTP / a HTML page... it doesn't work... The perl file needs to run an ASP page and then get the text generated by the ASP page, then the perl file will take the text and create a text file on the server.It works on the server, but it doesn't work when I call it on HTTP / with a HTML page... Please give a hand~ urgent~! :)

Link to comment
Share on other sites

if you are not calling it in a browser (on the server) how are you running it? Command line?
Using runtime... Command line is: Perl filename.plThen it takes & creates a file on the server... but when I run this filename.pl on HTTP / with a HTML file... it doesn't call the ASP page nor create the file which should pick up the output of the ASP page... ><
Link to comment
Share on other sites

hmm... and both scripts are identical you are just runnin gthem with a different method? When you say you run it with HTTP what do you type in the address bar of the browser? Do you type the absolute path (C:\perlscripts\myscript.pl) or do you use a web server (Apache or IIS) (localhost/myscript.pl)?

Link to comment
Share on other sites

>>my $req = $ua->request(HTTP::Request->new( GET => $url ));This line should be the problem... cuz it may not work on HTTP but only the server side?Do you know the correct script for running it on HTTP if possible? If impossible, how could I do it?

>>my $req = $ua->request(HTTP::Request->new( GET => $url ));This line should be the problem... cuz it may not work on HTTP but only the server side?Do you know the correct script for running it on HTTP if possible? If impossible, how could I do it?
The followings are the files... the HTML page will call the SECOND FILE... which works perfectly... but it doesn't work for the FIRST FILE's sub(function) getdata... but it works perfectly on the server page...I think the problem is that the HTTP::Request problem... this script should be for running on server side only... does anyone know the script running it on HTTP?FIRST FILE: callasp_storyman.pl#!/usr/bin/perluse warnings;use strict;use CGI qw(:standard);use CGI qw/escape/;use LWP::UserAgent;my $cgi_object = CGI->new();my $url = 'http://mywords.ust.hk/STU/games/game_getdata_storyman.asp';my $file = 'eotw_word_lists_storyman';my $ua = LWP::UserAgent->new();sub getdata {my $req = $ua->request(HTTP::Request->new( GET => $url ));#$req->header('Accept' => '*_/*');my $content = $req->content;my @lines = split("\n",$content);chomp(@lines);my $line;#Sent to a text fileif (unlink($file) == 0) {} else {}sysopen (OUT, $file, 0755, 0755);foreach $line (@lines){print OUT "$line\n"; }close(OUT);}return 1;SECOND FILE: eotw_load_data_storyman.pl#!/usr/local/bin/perlrequire "callasp_storyman.pl";require "eotw_lib.pl";use strict;use CGI qw(:standard);use CGI qw/escape/;my $cgi_object = CGI->new();my $the_list_id;main();sub main() {check_server();validate();#getdata(); get_send_values();}sub get_send_values {my $c_storyman_words_file = "eotw_word_lists_storyman";my $vTheWords;my $vTheTopic;my $i;my $dummy;getdata(); open(WORDS_FILE, $c_storyman_words_file);my @storyman_words = <WORDS_FILE>;close(WORDS_FILE);for ($i=0; $i<@storyman_words; $i++) {if (substr($storyman_words[$i],0,2) == $the_list_id) {($dummy,$vTheTopic) = split(/\|/,$storyman_words[$i]);$vTheWords = $storyman_words[$i+1];last;}}chomp($vTheTopic);chomp($vTheWords);chop($vTheWords); print "Content-type: application/x-www-urlform-encoded\n\n";print "&vTheWords=".escape("${vTheWords}")."&vTheTopic=".escape("${vTheTopic}");}sub validate {print "content-type: text/html \n\n"; $the_list_id = $cgi_object->param("id");if (!$the_list_id) {$the_list_id=1;}die "One of the fields contained inappropriate characters\n" if($the_list_id =~ s/<!--(.|\n)*-->//g);}QUOTE(aspnetguy @ Aug 22 2006, 07:45 PM) hmm... and both scripts are identical you are just runnin gthem with a different method? When you say you run it with HTTP what do you type in the address bar of the browser? Do you type the absolute path (C:\perlscripts\myscript.pl) or do you use a web server (Apache or IIS) (localhost/myscript.pl)?Thanks so much for helping, first of all~ ^^I do use the web server to run it... I think everything is correct except for the script of FIRST FILE... ><I think that the script should be different for running it on server & HTTP, is it?If not, then there must be something else which I don't know... ><
Link to comment
Share on other sites

when you say the file doesn't work runnin git over the web what do you mean? Do you get any error messages? Or does nothing happen?If you get errors please post them, if nothing happens is there a function to check if $req is set or not (PHP equivelant isset()) If this is not being set properly you will not any further.

Link to comment
Share on other sites

when you say the file doesn't work runnin git over the web what do you mean? Do you get any error messages? Or does nothing happen?If you get errors please post them, if nothing happens is there a function to check if $req is set or not (PHP equivelant isset()) If this is not being set properly you will not any further.
Thanks a lot~! I'm using brower to run the perl file... do you mind to tell me how to check the errors...? ><
Link to comment
Share on other sites

If there are runtime erros they would show in the browser in big black letters like thisInternal Server Error
Yeah, that's what it shows on the browser... I thought you're asking for the Apache log error which I don't quite remember how to get it........ ><
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...