LIBWWW - Command Line vs Web Browser 
Author Message
 LIBWWW - Command Line vs Web Browser

I don't consider myself to be a "newbie" to PERL, but an a neophyte.

I am trying to use the LIBWWW package to POST some data to a "foreign" website
and extract the portion I want from the reply. It was surprisingly easy to get
the package working with PERLIS (307) under WinNT.

I wrote a test script that POSTS to the target site and extracts the results
and it works fine from the command line, but gives back

        "RC: 500 (Internal Server Error)
        Message: Unexpected EOF at C:\Program
        Files\perl5\lib/LWP/Protocol/ line 171"

when executed from a web browser.

The program is modified from the excellent little "cookbook" that comes in the
distribution. The "cookbook" code is in a subroutine along with the parameters
for the POST needed by the foreign site. The sub is called, the reply is
stripped to teh part we want and the results printed.

        use URI::URL;
        use LWP::UserAgent;

        print "HTTP/1.0 200 OK\r\n" if $ENV{PERLXS} eq "PerlIS";
        print "Content-type: text/html\n\n";


        # fix up table that was given back to us to use on our site
        $table =~ s/<TD>/$td_form1/gi;

        print "<html><body>$flag";
        print "<center><table width=\"500\" border=\"0\">";
        print $table;
        print "</table></center>";

        print "</body></html>";


sub get_data()
        $target = ' http://www.*-*-*.com/ ';

        # target system parameters here

        %form = (parameters);

        $ua = new LWP::UserAgent;

        my $req = new HTTP::Request 'POST', $target;
        my $curl = url("http:");      # create an empty HTTP URL object
        $req->content($curl->equery); # %form content as escaped query string

        $reply = $ua->request($req)->as_string;

        # do a dirty parse to pick up the table that is in the reply
        # returns everything inside the <TABLE>...</TABLE> block

        if ($reply =~ /<TH>Highest<\/tr>/ && $' =~ /<\/TABLE/)
                $table = "$`";


        # and return it


I know the PERLIS is OK, its working with dozens of other browser initiated
programs. And as I said, the script appears to be OK as it works from the
command line.

Can someone give me a clue as to what is wrong here?



Sun, 27 Feb 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. executing commands, command-line vs. browser

2. Question: command line with perl and Web browser

3. -ln015 on #! line -vs- command line

4. web site vs. browsers

5. work on command line and not via browser?

6. Executes under command-line not through the browser

7. browser output different from command line

8. Win32::OLE problem -- command line vs. CGI

9. command line parameters (.bat vs .pl)

10. price of perl (was Re: GUI vs command line)

11. Command line script vs modules/subroutines


Powered by phpBB® Forum Software