title: Adding the contentType: "application/json" make error
body: <p>I want to have a service that calls from an HTML file. for example like this:</p>
  
  <pre><code>// POST api/values
  public ActionResult Post([FromBody]Models.FormEntry[] composit)
  {
      //Some Code here ...
  
      return new HttpStatusCodeResult(200);
  }
  </code></pre>
  
  <p>then I call this service from an HTML file like below:</p>
  
  <pre><code>&lt;script&gt;
      function onSubmit(form) {
          var data = $(form).serializeArray();
              $.ajax({
                  type: "POST",
                  url: "http://localhost:45407/api/values",
                  data: JSON.stringify(data),
                  dataType: "text",
                  //contentType: "application/json",
                  success: function () { alert('YES!'); },
                  error: function () { alert('NO NO NO!'); }});
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>its behave nomally but sending nothing to service, and the <code>composit</code> argument gives null value. when I Uncomment the <code>contentType: "application/json"</code> it makes error and service doesn't call.
  I test it by the postman (Chrome extension) and it works perfectly. the postman recommends me this code:</p>
  
  <pre><code>var settings = {
      "async": true,
      "crossDomain": true,
      "url": "http://localhost:45407/api/values",
      "method": "POST",
      "headers": {
          "content-type": "application/json",
          "cache-control": "no-cache",
          "postman-token": "e1b9721b-2925-c413-69e0-b1b21de239cb"
        },
        "processData": false,
        "data": data
      }
  
      $.ajax(settings).done(function (response) {
            console.log(response);
      });
  </code></pre>
  
  <p>I replace above code with mine, but the service call still has an unknown error. I think it is maybe a security consideration, that we not allow to sent requests from <code>localhost</code>, for this reson I add <code>&lt;httpProtocol&gt;</code> under the <code>&lt;system.webServer&gt;</code> tag in service web.config file like this:</p>
  
  <pre><code>&lt;httpProtocol&gt;
    &lt;customHeaders&gt;
    &lt;add name="Access-Control-Allow-Origin" value="*" /&gt;
    &lt;add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,PUT,DELETE" /&gt;
    &lt;add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept, soapaction" /&gt;
    &lt;/customHeaders&gt;
  &lt;/httpProtocol&gt;
  </code></pre>
  
  <p>for this problem, I saw this links:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/22531166/contenttype-application-json-with-post-method-javascript">contentType: 'application/json' with POST method (JavaScript)</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/2845494/jquery-jqgrid-breaks-when-contenttype-application-json">Jquery JQGrid breaks when contentType=application/json?</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/42694651/ajax-post-call-with-application-json-contenttype-gets-no-access-control-allow">AJAX POST call with application/json contentType gets “no 'Access-Control-Allow-Origin' header” error</a></p></li>
  </ul>
  
  <p>So how can I call a Restful service from an HTML file and sent a JSON array in the request body, by setting a true Content Type?</p>