Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Perl LWP::Agent with Apache Server

    Hi,

    I'm trying to execute a simple perl cgi script in Apache Tomcat Server with CGI Servlet.

    My perl cgi script:
    -------------------
    #!/usr/bin/perl -w

    use LWP::UserAgent;
    use HTTP::Request::Common;

    print "Content-Type: text/html\n\n";

    my $url = 'http://127.0.0.1:8080/cgi-bin/test.pl';
    my $content = "name=jagadish";

    my $headers = new HTTP::Headers(Content_Type => "text/html",
    Content_Length => length($content));
    my $request = new HTTP::Request('POST' => $url, $headers, $content);

    my $ua = new LWP::UserAgent;
    my $response = $ua->request($request);

    print $response->as_string, "\n";

    exit 1;

    ------------

    When I try to call this script in the browser, all I get is the below error in the browser window,

    500 Can't connect to 127.0.0.1:8080 (Unknown error) Content-Type: text/plain Client-Date: Wed, 24 Nov 2010 17:53:56 GMT Client-Warning: Internal response 500 Can't connect to 127.0.0.1:8080 (Unknown error)

    If I execute the above script from the command like (just like any other stand alone perl script), it just works fine.

    The problem occurs only when the script is executed by the apache server. I don't what I'm doing wrong here.

    My System Configuration:
    Windows Server 2003
    Apache Tomcat Server with CGI Servlet Enabled
    Perl 5.10.1

    Any help would be appreciated...

    Let me know, if you need more information

    Thanks
    Jagadish G

  • #2
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    At last, I made it working myself. The problem was in the Apache Tomcat CGI Servlet configuration. You will have to configure it to pass shell environmental variables to your CGI script as below,

    <servlet>
    <servlet-name>cgi</servlet-name>
    <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
    .
    .
    .
    <init-param>
    <param-name>passShellEnvironment</param-name>
    <param-value>true</param-value>
    </init-param>
    .
    .
    .
    </servlet>

    Hope this helps anyone struggling with this problem

    Thanks
    Jagadish


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •