title: Error sending WebRequest to Spreedly with C# : (422) Unprocessable Entity
body: <p>I'm working with Spreedly, and I'm running into what I would assume is a minor problem.</p>
  
  <p>For the life of me I don't understand why my code isn't sending my context correctly... </p>
  
  <p>This is my code (credentials have been changed) that returns the error (422) Unprocessable Entity, which I can only assume means something is wrong with the XML that is being sent, but it appears to be correct when I set a break point.</p>
  
  <pre><code>string url = "https://core.spreedly.com/v1/gateways.xml";
  WebRequest request = WebRequest.Create(url);
  request.ContentType = "Content-type: application/xml";
  request.Method = "POST";
  request.Credentials = new NetworkCredential("Ll6fAtoVSTyVMlJEmtpoJV8Shw5", "RKOCG5D8D3fZxDSg504D0IxU2XD4Io5VXmyzdCtTivHFTTSylzM2ZzTWFwVH4ucG");
  XElement xelement = new XElement("gateway", new XElement("gateway_type", "test"));
  byte[] buffer = Encoding.UTF8.GetBytes(xelement.ToString());
  request.ContentLength = buffer.Length;
  Stream reqstr = request.GetRequestStream();
  reqstr.Write(buffer, 0, buffer.Length);
  reqstr.Close();
  WebResponse response = request.GetResponse();
  </code></pre>
  
  <p>I don't use WebRequest often, so it's more than plausible that I'm missing something simple.</p>
  
  <p>Spreedly keeps their documentation <a href="https://docs.spreedly.com/" rel="nofollow">here</a>.</p>
  
  <p>The examples are in curl and say I should be sending the following:</p>
  
  <pre><code>$ curl https://core.spreedly.com/v1/gateways.xml \
  -u 'Ll6fAtoVSTyVMlJEmtpoJV8Shw5:RKOCG5D8D3fZxDSg504D0IxU2XD4Io5VXmyzdCtTivHFTTSylzM2ZzTWFwVH4ucG' \
  -H 'Content-Type: application/xml' \
  -d '&lt;gateway&gt;
        &lt;gateway_type&gt;test&lt;/gateway_type&gt;
      &lt;/gateway&gt;'
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thank you.</p>