title: Manually post to an Asp.Net MVC controller
body: <p>I have a controller that looks like this for importing xml to my site:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Import(string xml)
      {
  </code></pre>
  
  <p>I have a standalone application that reads an xml file and sends it to the url. It looks like this:</p>
  
  <pre><code>    static void Main(string[] args)
      {
          var reader = new StreamReader(@"myfile.xml");
          var request = WebRequest.Create("http://localhost:41379/mycontroller/import");
          request.Method = "POST";
          request.ContentType = "text/xml";
          StreamWriter sw = new StreamWriter(request.GetRequestStream());
          sw.Write(reader.ReadToEnd());
          sw.Close();
          var theResponse = (HttpWebResponse)request.GetResponse();
          StreamReader sr = new StreamReader(theResponse.GetResponseStream());
          var response = sr.ReadToEnd();
      }
  </code></pre>
  
  <p>The controller gets called properly, but when I break in there, the argument is null. I am pretty sure I am just not setting the right content type or something like that. What is the proper way to encode the xml so that the framework will get it and give it to the controller properly?</p>