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.
Asked
Active
Viewed 4,229 times
4
-
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 Answers
10
HTTParty.post url, :body => xml, :headers => {'Content-type' => 'text/xml'}

Michaël Witrant
- 7,525
- 40
- 44
-
Thanks! Yeah, that's what I was trying to do... I was just making a noob mistake someplace else. :) – Claudio Lassala Jul 31 '11 at 05:24