Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

HTTP POST error

by Anonymous Monk
on May 27, 2014 at 20:50 UTC ( #1087577=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

In the code i am trying to sort the files in ascending order and sending the data which are present in the files. BUT GETTING error message :( code which will send multiple xml files..
#!/usr/bin/perl #use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $server_endpoint = "http://localhost/cgi-bin/process.cgi"; # set custom HTTP Request header fields my $req = HTTP::Request->new(POST => $server_endpoint); $req->header('content-type' => 'text/xml'); $req->content($xml); my @files = (glob("*.xml")); print "@files\n"; foreach $test(@files){ #print "this element: $test \n "; open FILE, $test or die $!; # my $lineno=1; while(<FILE>){ $xml = $_; print $xml; } } my $resp = $ua->request($req); if ($resp->is_success){ my $message = $resp->decoded_content; print "Received reply:\n $message\n"; } else { print "HTTP POST error code: ", $resp->code, "\n"; print "HTTP POST error message: ", $resp->message, "\n"; } <code> code which will receive multiple xml files.. <code> #!/usr/bin/perl use strict; use CGI; use DBI; use XML::Twig; use CGI::Carp 'fatalsToBrowser'; my $cgi = CGI->new; print $cgi->header(-type => "text/xml", -charset => "utf-8"); my $xml = $cgi->param("POSTDATA"); print $xml received;
ERROR MESSAGE: HTTP POST error code: 500 HTTP POST error message: Internal Server Error

Comment on HTTP POST error
Download Code
Re: HTTP POST error
by taint (Chaplain) on May 27, 2014 at 21:12 UTC
    I'm going to fore go temtation to evaluate your code, and suggest, given the error coode HTTP 500. That this has more to do with permissions, than the code itself. In other words; it appears that your script, or the files that it attempts to access, do NOT have permission to either READ, or WRITE, or EXECUTE, under the ownership of the user that the scripts are owned. see chmod, chown, for hints to this. As well as the Web Server software, that manages the scripts/files.

    Best wishes

    --Chris

    λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH

Re: HTTP POST error
by hippo (Curate) on May 27, 2014 at 21:53 UTC

    You'll get the HTTP 500 error because your server-side script won't even compile. The problem is on the last line:

    Bareword "received" not allowed while "strict subs" in use at f.cgi li +ne 13.

    A look at the web server error log (or indeed at the page returned) would tell you that.

Re: HTTP POST error
by Anonymous Monk on May 28, 2014 at 19:54 UTC

    Hi Monks, HTTP ERROR problem solved.Thanks But still i am not able to receive data. Is there any modification required or error in my code..?

      You have this line before reading any files hence you are not sending any data.
      $req->content($xml);

      Try moving it to after foreach loop

      foreach my $file (@files){ open FILE, $file or die $!; while (<FILE>){ $xml .= $_; } } $req->content($xml);
      Assuming you want to send all the data in one post.
      poj
Re: HTTP POST error
by Anonymous Monk on May 29, 2014 at 19:03 UTC
    done thanx a ton to all..
Re: HTTP POST error
by Anonymous Monk on May 30, 2014 at 08:17 UTC
    can i set timer of 2min?..in loop condition..so that the program should send files in every two minutes..

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1087577]
Approved by GotToBTru
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-09-20 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (159 votes), past polls