+ Reply to Thread
Results 1 to 3 of 3

Thread: Perl 500 internal server error. Something wrong with my code.

  1. #1
    nitrad is offline x10Hosting Member nitrad is an unknown quantity at this point
    Join Date
    May 2010
    Posts
    1

    Question Perl 500 internal server error. Something wrong with my code.

    I get a 500 internal server error when I try to run the code below:
    Code:
    #! /usr/bin/perl
    
    use LWP;
    
    my $ua = LWP::UserAgent->new;
    $ua->agent("TestApp/0.1 ");
    $ua->env_proxy();
    
    my $req = HTTP::Request->new(POST => 'http://www.google.com/loc/json');
    
    $req->content_type('application/jsonrequest');
    $req->content('{ "cell_towers": [{"location_area_code": "55000", "mobile_network_code": "95", "cell_id": "20491", "mobile_country_code": "404"}], "version": "1.1.0", "request_address": "true"}');
    
    my $res = $ua->request($req);
    if ($res->is_success) {
        print $res->content,"\n";
    } else {
        print $res->status_line, "\n";
        return undef;
    }
    But there is no error when I run the code below:
    Code:
    #! /usr/bin/perl
    
    use CGI::Carp qw(fatalsToBrowser);
     
    
    print "Content-type: text/html\n\n";
    print "<HTML>\n";
    print "<HEAD><TITLE>Hello World!</TITLE></HEAD>\n";
    print "<BODY>\n";
    print "<H2>Hello World!</H2> <br /> \n";
     
    foreach $key (sort keys(%ENV)) {
      print "$key = $ENV{$key}<p>" ;
    }
    print "</BODY>\n";
    print "</HTML>\n";
    So I think there is some problem with my code. When I run the first perl script in my local machine with the -wc command, it says that the syntax is OK. Help me please.
    Last edited by nitrad; 05-20-2010 at 03:25 AM.

  2. #2
    ZymeX is offline x10Hosting Member ZymeX is an unknown quantity at this point
    Join Date
    May 2010
    Posts
    6

    Re: Perl 500 internal server error. Something wrong with my code.

    Are your page properties set correctly? Most perl scripts either have pages set at 755 or 777 but it all depends on the script. So try doing that first and if it doesn't work let me know.

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Perl 500 internal server error. Something wrong with my code.

    One issue is you're not printing any response headers, so the response body is treated as the response headers. Since the body isn't valid as headers, you're getting a 500 error. Try adding:

    Code:
    use CGI ':standard';
    ...
    if ($res->is_success) {
        print header(-type => $res->header('Content-type'));
        print $res->content,"\n";
    } else {
        print header(-status => $res->status_line);
        # should print an error response body 
        return undef;
    }
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Replies: 5
    Last Post: 04-23-2010, 05:43 AM
  2. Perl with CGI, internal server error?
    By rallan in forum Free Hosting
    Replies: 2
    Last Post: 08-16-2009, 02:39 PM
  3. 500 Internal Server Error with perl script
    By erko1 in forum Free Hosting
    Replies: 5
    Last Post: 05-30-2008, 10:47 AM
  4. Internal Server Error FOR Perl script
    By radofeya in forum Free Hosting
    Replies: 0
    Last Post: 04-14-2008, 01:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers