receiving an XML POST via CGI


Frank Reiff


I'm a competent enough Objective-C and Java programmer, but I'm still
having the occasional problem getting my head around the "Ruby way". The
class that gives me most headaches is CGI..

I've got a script running on Apache mod_fcgi that receives an HTML POST
containing an XML message from another server (a light weight web
service). I parse this message and send emails, update databases and
logs based on its content.

My problem is that it works 99% of the time, but sometimes the XML gets
split and reassembled incorrectly, e.g.

<?xml version"1.0" encoding="UTF-8"?>
<request>..lots of stuff..</request>

occasionally arrives as:

<request<?xml version"1.0" encoding="UTF-8"?>..lots of stuff..</request>

Obviously at that stage REXML is packing in as the XML string is
incorrectly formatted.

Now something tells me that the problem might well be in the way I use
the CGI class to get to the POST data:

# gets a cgi object from the FCGI dispatcher
FCGI.each_cgi { |cgi|

# prints the parameters to the standard error for debugging
$stderr.puts "cgi.params: #{cgi.params}"

# parse the parameters
doc = cgi.params.to_s

I'm wondering whether there is any "ruby magic" to the cgi.params call.
I never quite understand what's actually in there, is it a simple
string, a hash of strings or an array of hashes or a hash of hashes or
sometimes one and sometimes another.. I'm sure it's frightfully
convenient, but I can't get my head around it..

The documentation simply confuses me even further.. it just looks like
my string re-assembly problem might stem from there..

Any help would be much appreciated.

Best regards,


Frank Reiff

After investigation, the problem turns out the be elsewhere.. the
$stderr was misleading because it was escaped..

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Latest member

Latest Threads