title: httr POST API request but missing xml parameter
body: <p>I am trying to connect to the XML API for IBM Silverpop using <code>httr</code>, but I am running into a 'missing XML parameter' problem. I tried using the test harness provided by Silverpop to see if the requests I am sending is different in comparison to what I send via <code>httr</code>, but haven't found anything to help me.</p>
  
  <p>Following is the <code>XML</code> body I send when using the <strong>test harness</strong> which succeeds:</p>
  
  <pre><code>&lt;Envelope&gt;&lt;Body&gt;
  &lt;Login&gt;
  &lt;USERNAME&gt;My Email&lt;/USERNAME&gt;
  &lt;PASSWORD&gt;My password&lt;/PASSWORD&gt;
  &lt;/Login&gt;
  &lt;/Body&gt;&lt;/Envelope&gt;
  </code></pre>
  
  <p>Using Chrome to inspect the <strong>request headers</strong> (using <code>CTRL + SHIFT + I</code>):</p>
  
  <pre><code>Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Accept-Encoding:gzip, deflate
  Accept-Language:en-US,en;q=0.8
  Cache-Control:max-age=0
  Connection:keep-alive
  Content-Length:225
  Content-Type:application/x-www-form-urlencoded
  Host:api3.silverpop.com
  Origin:null
  Upgrade-Insecure-Requests:1
  User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36
  </code></pre>
  
  <p>Again, using Chrome to inspect <strong>response headers</strong>:</p>
  
  <pre><code>Connection:Keep-Alive
  Content-Type:text/xml;charset=utf-8
  Date:Fri, 04 Dec 2015 12:15:34 GMT
  Keep-Alive:timeout=15, max=100
  Server:Apache-Coyote/1.1
  Transfer-Encoding:chunked
  </code></pre>
  
  <p>Using <code>httr</code>, I construct my request as follows:</p>
  
  <pre><code>library(httr)
  
  ibmUrl &lt;- "api3.silverpop.com/XMLAPI"
  
  body1 &lt;- "&lt;Envelope&gt;&lt;Body&gt;
  &lt;Login&gt;
  &lt;USERNAME&gt;My Email&lt;/USERNAME&gt;
  &lt;PASSWORD&gt;My password&lt;/PASSWORD&gt;
  &lt;/Login&gt;
  &lt;/Body&gt;&lt;/Envelope&gt;"
  
  test1 &lt;- POST(url = ibmUrl, body = body1, verbose(), content_type("application/x-www-form-urlencoded"))
  </code></pre>
  
  <p>Using <code>verbose()</code> shows the following being sent and received:</p>
  
  <pre><code>-&gt; POST /XMLAPI HTTP/1.1
  -&gt; Host: api3.silverpop.com
  -&gt; User-Agent: libcurl/7.43.0 r-curl/0.9.3 httr/1.0.0
  -&gt; Accept-Encoding: gzip, deflate
  -&gt; Accept: application/json, text/xml, application/xml, */*
  -&gt; Content-Type: application/x-www-form-urlencoded
  -&gt; Content-Length: 132
  -&gt; 
  &gt;&gt; &lt;Envelope&gt;&lt;Body&gt;
  &gt;&gt; &lt;Login&gt;
  &gt;&gt; &lt;USERNAME&gt;My Email&lt;/USERNAME&gt;
  &gt;&gt; &lt;PASSWORD&gt;My password&lt;/PASSWORD&gt;
  &gt;&gt; &lt;/Login&gt;
  &gt;&gt; &lt;/Body&gt;&lt;/Envelope&gt;
  
  &lt;- HTTP/1.1 200 OK
  &lt;- Date: Fri, 04 Dec 2015 13:29:55 GMT
  &lt;- Server: Apache-Coyote/1.1
  &lt;- Content-Type: text/xml
  &lt;- Content-Length: 255
  </code></pre>
  
  <p>But when I inspect the response from the API using <code>content()</code>, I get the following:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;Envelope&gt;
    &lt;Body&gt;
      &lt;RESULT&gt;
        &lt;SUCCESS&gt;false&lt;/SUCCESS&gt;
      &lt;/RESULT&gt;
      &lt;Fault&gt;
        &lt;Request/&gt;
        &lt;FaultCode/&gt;
        &lt;FaultString&gt;Missing 'xml'parameter&lt;/FaultString&gt;
        &lt;detail&gt;
          &lt;error&gt;
            &lt;errorid&gt;52&lt;/errorid&gt;
            &lt;module/&gt;
            &lt;class&gt;SP.API&lt;/class&gt;
            &lt;method/&gt;
          &lt;/error&gt;
        &lt;/detail&gt;
      &lt;/Fault&gt;
    &lt;/Body&gt;
  &lt;/Envelope&gt;
  </code></pre>
  
  <p>How come?</p>
  
  <p>Thanks in advance.</p>