title: ASP.NET POST request to same host results in a null payload
body: <p>I want to hit some ASP.NET APIs from the same application that hosts the APIs. The real world use case is that I want to upload a file to an MVC controller, parse it out and make a bunch of separate API calls via POST requests to APIs that are hosted on the same application. I can see that the appropriate API endpoints are getting hit by setting a breakpoint inside of the WebApi controller method, but the payload is always null. I've tried using Flurl, RestSharp, WebClient, and WebRequest to make the request, and none of them allow the payload to make it through. It also fails with the null payload problem if I try to invoke these POST requests via unit/integration tests.</p>
  
  <p>Is there some sort of built in limitation to the ASP.NET framework that prevents a payload from being posted to the same application?</p>
  
  <pre><code>var myObjectRow = new JObject();
  myObjectRow["Key"] = 1;
  
  
  /* RestSharp */
  var request = new RestRequest("/api/MyObject", Method.POST);
  request.AddHeader("Content-type", "application/json; charset=utf-8");
  request.AddBody(request.JsonSerializer.Serialize(myObjectRow));
  request.AddJsonBody(myObjectRow);
  request.AddParameter("Application/Json", myObjectRow, ParameterType.RequestBody);
  var response = RestClient.Execute&lt;MyObject&gt;(request);
  
  
  /* WebClient */
  using (var webClient = new WebClient())
  {
      webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
      var payload = JsonConvert.SerializeObject(myObjectRow);
      var response = webClient.UploadString(BaseUrl + "/api/MyObject", "POST", payload);
  }
  
  
  /* WebRequest */
  var payload = JsonConvert.SerializeObject(myObjectRow);
  byte[] buf = Encoding.UTF8.GetBytes(payload);
  var request = (HttpWebRequest)WebRequest.Create(BaseUrl + "/api/MyObject");
  request.Method = "POST";
  request.ContentLength = buf.Length;
  request.ContentType = "application/json; charset=utf-8";
  request.GetRequestStream().Write(buf, 0, buf.Length);
  
  using (var response = (HttpWebResponse)request.GetResponse())
  {
      var responseStream = response.GetResponseStream();
      var streamReader = new StreamReader(responseStream, Encoding.UTF8);
      var responseString = streamReader.ReadToEnd();
  }
  </code></pre>
  
  <p>The target endpoint is something like this:</p>
  
  <pre><code>public class MyObjectController : ApiController
  {
      public MyObject Post(MyObject myObject)
      {
          // myObject shows up null here
          return myObject;
      }
  }
  </code></pre>