# Receiving an XML POST via CGI

**URL:** <https://www.ruby-forum.com/t/receiving-an-xml-post-via-cgi/122420>\
**Category:** Ruby\
**Created:** [December 7, 2007, 2:28pm UTC](https://www.ruby-forum.com/t/receiving-an-xml-post-via-cgi/122420 "2007-12-07T14:28:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![frocco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a87d85/32.png) [@frocco](https://www.ruby-forum.com/u/frocco)\
**Post date:** [December 7, 2007, 2:28pm UTC](https://www.ruby-forum.com/t/receiving-an-xml-post-via-cgi/122420/1 "2007-12-07T14:28:22Z")

</div>

Hi,

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 = Document.new 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

---

<div class="post-metadata">

**Author:** ![frocco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/a87d85/32.png) [@frocco](https://www.ruby-forum.com/u/frocco)\
**Post date:** [December 7, 2007, 7:13pm UTC](https://www.ruby-forum.com/t/receiving-an-xml-post-via-cgi/122420/2 "2007-12-07T19:13:41Z")

</div>

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