title: Ruby: HTTParty: can't format XML POST data correctly?
body: <p>NOTE: "object" is a placeholder work, as I don't think I should be saying what the controller does specifically.</p>
  
  <p>so, I have multiple ways of calling my apps API, the following works in the command line:</p>
  
  <pre><code>curl -H 'Content-Type: application/xml' -d '&lt;object&gt;&lt;name&gt;Test API object&lt;/name&gt;&lt;password&gt;password&lt;/password&gt;&lt;description&gt;This is a test object&lt;/description&gt;&lt;/object&gt;' "http://acme.example.dev/objects.xml?api_key=1234"
  </code></pre>
  
  <p>the above command generates the following request in the devlog:</p>
  
  <pre><code>Processing ObjectsController#create to xml (for 127.0.0.1 at 2011-07-07 09:17:51) [POST]
    Parameters: {"format"=&gt;"xml", "action"=&gt;"create", "api_key"=&gt;"1234", "controller"=&gt;"objects", 
    "object"=&gt;{"name"=&gt;"Test API object", "description"=&gt;"This is a test object", "password"=&gt;"[FILTERED]"}}
  </code></pre>
  
  <p>Now, I'm trying to write tests for the actions using the API, to make sure the API works, as well as the controllers.
  Here is my current (broken) httparty command:</p>
  
  <pre><code>  response = post("create", :api_key =&gt; SharedTest.user_api_key, :xml =&gt; data, :format =&gt; "xml")
  </code></pre>
  
  <p>this command generates the following request in the testlog:</p>
  
  <pre><code>Processing ObjectsController#create to xml (for 0.0.0.0 at 2011-07-07 09:37:35) [POST]
    Parameters: {
          "xml"=&gt;"&lt;object&gt;&lt;name&gt;&lt;![CDATA[first post]]&gt;&lt;/name&gt;
                      &lt;description&gt;&lt;![CDATA[Things are not as they used to be]]&gt;&lt;/description&gt;
                      &lt;password&gt;&lt;![CDATA[WHEE]]&gt;&lt;/password&gt;
                  &lt;/object&gt;", 
                  "format"=&gt;"xml", 
                  "api_key"=&gt;"the_hatter_wants_to_have_tea1", 
                  "action"=&gt;"create", 
                  "controller"=&gt;"objects
  </code></pre>
  
  <p>So, as you can see, the command line command actually generates the object hash from the xml, whereas the httparty command ends up staying in xml, which causes problems for the create method, as it needs a hash.</p>
  
  <p>Any ideas / proper documentation?
  Current documentation says that post takes an url, and "options" and then never says what options are available</p>
  
  <hr>
  
  <p>*<strong>*EDIT</strong>:<br>
  as per @Casper's suggestion, my method now looks like this: </p>
  
  <pre><code>def post_through_api_to_url(url, data, api_key = SharedTest.user_api_key)
  
    response = post("create", {
      :query =&gt; {
        :api_key =&gt; api_key
      },
      :headers =&gt; {
        "Content-Type" =&gt; "application/xml"
      },
      :body =&gt; data
    })
    ap @request.env["REQUEST_URI"]
    assert_response :success
  
    return response
  end
  </code></pre>
  
  <p>unfortunately, the assert_response fails, because the authentication via the api key fails. 
  looking at the very of of the request_uri, the api_key isn't being set properly... it shows:</p>
  
  <pre><code>api_key%5D=the_hatter_wants_to_have_tea1"
  </code></pre>
  
  <p>but it should just be equals, without the %5D (right square bracket)</p>