title: Sending XML payloads with HTTP POST request using HttpClient--Java
body: <p>So I've been doing a lot of looking on both stackoverflow and google in general to try and answer my following question, but I have been unable to find anything that can help me to get this work 100%. I'm pretty sure I have everything except a SMALL error correct, but obviously you guys probably have suggestions anyway, so go for it!</p>
  
  <p>And, here we go: I've been using HTTPClient to test an API on a few different environments, and I got HTTPPost methods to accept JSON payloads but now I'm trying to send payloads using XML and I'm running into some issues. It seems that the XML string that I'm creating (in the code below) is correct... so I'm stumped as to why this isn't working. ALSO: got most of the DOM code from the internet (to build up the XML payload) so feel free to bring that into question as well...</p>
  
  <p>My code is the following: </p>
  
  <pre><code>DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
  
  Document doc = docBuilder.newDocument();
  Element subscription = doc.createElement("subscription");
  doc.appendChild(subscription);
  
  subscription.setAttribute("email", "patricia@test.intershop.de");
  etc....
  etc....
  etc....
  etc....
  
  DOMSource domSource = new DomSource(doc);
  StringWriter writer = new StringWriter();
  StreamResult result = new StreamResult(writer);
  TransformerFactory tf = TransformerFactory.newInstance();
  Transformer transformer = tf.newTransformer();
  transformer.transform(domSource, result);
  
  String XMLpayload = writer.toString();
  
  [name of my HttpRequest].setEntity(new StringEntity(XMLpayload));
  [name of my HttpResponse] = client.execute(request);
  </code></pre>
  
  <p>now... I'm looking to achieve the payload seen BELOW:</p>
  
  <pre><code>&lt;subscription&gt;
      &lt;email&gt;patricia@test.intershop.de&lt;/email&gt;
      &lt;firstName&gt;Patricia&lt;/firstName&gt;
      &lt;lastName&gt;Miller&lt;/lastName&gt;
      &lt;title&gt;Ms.&lt;/title&gt;
      &lt;gender&gt;Female&lt;/gender&gt;
  &lt;/subscription&gt;
  </code></pre>
  
  <p>When I print out the payload that I am sending currently it looks like the following:</p>
  
  <p>?xml version="1.0" encoding="UTF-8" standalone="no"? subscription email="patricia@test.intershop.de" firstName="Patricia" gender="Female" lastName="Miller" title="Ms."/</p>
  
  <p>(NOTE: I REMOVED THE &lt; AND > BRACKETS. THEY APPEAR WHERE THEY SHOULD!)</p>
  
  <p>But, I'm receiving a 400 error. Any ideas here? I know I have the proper headers, the URL is correct, etc. It's absolutely something with what I'm doing with the payload. Any thoughts would be greatly appreciated!!</p>
  
  <p>Best!</p>