4

I'm trying to make a POST request using HTTParty, in which I need the content-type to be text/xml. How can I make that happen? Right now the API I'm calling is complaining I'm not sending any xml. If I call it using curl I get the same error, unless I specify content-type to text/xml.

Michaël Witrant
  • 7,525
  • 40
  • 44
Claudio Lassala
  • 271
  • 3
  • 15
  • hmmm... apparently just by setting :body to the xml content already does the trick. However, the server still doesn't seem to be receiving the xml content... I'm at a loss now... – Claudio Lassala Jul 30 '11 at 19:26
  • Does the content type really need to be `text/xml` or do you only need a content type that states that the document is XML? In the latter case text/xml is usually not recommended (in favor of e.g. `application/xml`). Sending as `text/xml` always needs also a charset header or you need to encode your XML as ASCII. This is also W3C's take on this issue. http://www.w3.org/TR/webarch/#no-text-xml – jasso Oct 20 '11 at 17:54
  • Hmm... good question... I need to look into that. Thanks! – Claudio Lassala Oct 28 '11 at 13:22

1 Answers1

10
HTTParty.post url, :body => xml, :headers => {'Content-type' => 'text/xml'}
Michaël Witrant
  • 7,525
  • 40
  • 44