Problem (and solution): ActiveMerchant and Ruby 1.8.4

I recently lost a few hours debugging a Ruby issue that I thought I'd post in the hope of saving someone else the time.

Ruby 1.8.4's net/http library has a bug in the post method: the content-type header is not set by default. This can cause ActiveMerchant transactions to be rejected by the gateway for mysterious reasons.

The clean fix, if your server allows you to do so, is to upgrade to Ruby 1.8.5 or later.

Alternatively, at the start of the ssl_post method (in ActiveMerchant's posts_data.rb file), add this line at the start of the method:

  headers['content-type'] = 'application/x-www-form-urlencoded'

Michael Slater www.buildingwebapps.com