Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things


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

Replies are listed 'Best First'.
Re: HTTP POST error
by hippo (Abbot) 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 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


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

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.

      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.
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? loop that the program should send files in every two minutes..

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1087577]
Approved by GotToBTru
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2017-08-19 22:55 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (312 votes). Check out past polls.