?
Solved

Reading HTTP POST

Posted on 2004-11-21
8
Medium Priority
?
255 Views
Last Modified: 2010-03-05
Hello,

Here is the situation, a service will send some data to my web server using HTTP POST method. I need to catch that data and save it into a text file. The data is in XML format.

Anyone know how to do this in Perl ?

I got a PHP example below. It is working perfectly, but I need Perl version because I cant find a "good" way to read XML using PHP.

PHP example :

<?php

$xmlstring = '';

function getxml()
{
GLOBAL $xmlstring;

  $handle_i = fopen('php://input', "r");

  do
  {
    $xml = fread($handle_i, 2048);
    if (strlen($xml) == 0)
    {
      break;
    }

    $dummy .= $xml;

  } while (true);

  $dummy2 = urldecode($dummy);
  $xmlstring = str_replace("&", "", $dummy2);
  fclose($handle_i);
  return 0;
}

getxml();

$fname = "order.txt";
$fd = fopen($fname, "w");
fwrite($fd, $xmlstring);
fclose($fd);

?>


0
Comment
Question by:db2trade
5 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 12639887
Can you give an example of the XML data that's sent in the HTTP POST?
0
 
LVL 85

Expert Comment

by:ozo
ID: 12642678
I'm not sure what you're asking.  It sounds like what you need may be as simple as

use LWP::Simple;
print STDERR status_message getstore("php://input", "order.txt"),"\n";

perhaps also using XML::Dumper or XML::Simple


0
 
LVL 1

Author Comment

by:db2trade
ID: 12643552
The server will send XML data for about 2 KB size if saved into a text file.

It is just a basic xml. The XML here is not the problem. What I am looking for is how to capture data that is sent from a server using HTTP POST.

SERVER_A will send data to SERVER_B using HTTP POST.

I only have a PHP script (see my first post), it is working fine, the data will be saved into a text file. Now I need a perl version if you could help me.
0
 
LVL 7

Accepted Solution

by:
rugdog earned 400 total points
ID: 12647230
I assume SERVER B will use a CGI to respond to the request? if so:

#!/usr/bin/perl
use CGI;

open(O,"> order.txt") or die "failed to open file: $!\n";
while(<STDIN>){
  print O CGI::unescapeHTML($_);
}
close(O);

print "content-type: text/html\n\n";
print "done";
0
 
LVL 48

Expert Comment

by:Tintin
ID: 12651249
what does

php://input,r

do?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question