Receiving an XML POST via CGI


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"?>

…lots of stuff…

occasionally arrives as:

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

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,


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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs