title: ASP Web API POST request with CORS and IE9 (XDomainRequest object)
body: <p>I've been going crazy here trying to get jquery.ajax to work with ie9. So I have a ASP Web API 2 Rest API that implements CORS. CORS requests from all browsers work. IE9 didnt work since it uses the XDomainRequest. I managed to get it too work by making a custom implementation of ajaxTransport for IE9.</p>
  
  <p>Right now GET requests seem to work fine. But when I do a post request from IE9 I get a HTTP error 415 - unsuportted media type.</p>
  
  <p>I've set the content-type to:"application/json" and I've also tried "application/x-www-form-urlencoded", but from what I understood XDomainRequest doesnt support everything with custom headers? Does anybody know if something specific needs to be setup on the WebAPI or do I need to tweak the request?</p>
  
  <p>My request looks like this:</p>
  
  <pre><code>                        $.ajax({
                          url: hostname + "/api/DDC/Book",
                          type: "POST",
  
                          contentType: "application/json",
                          data: {
                              DealID: function () {
                                  return viewModel.get("DealID");
                              },
                              LocationID: function () {
                                  return viewModel.get("LocationID");
                              },
                              Time: function () {
                                  return viewModel.get("selectedDateTime.Time");
                              }
  
                          }
                      })
  </code></pre>
  
  <p>On the server I have this:</p>
  
  <pre><code>[HttpPost("DDC/Book")]
      [EnableCors(origins: "*", headers: "*", methods: "POST, GET, OPTIONS, PUT, DELETE")]
      public dynamic Post(BookModel model)
      {
         .........
  </code></pre>
  
  <p>When I analyze the failed request in the IE debugger this are the request headers that get sent out:</p>
  
  <pre><code>Key Value
  Request POST //api/DDC/Book HTTP/1.1
  Accept  */*
  Origin  http://myurl.com
  Accept-Language hr-HR
  Accept-Encoding gzip, deflate
  User-Agent  Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
  Host    www.somehost.com
  Content-Length  55
  DNT 1
  Connection  Keep-Alive
  Cache-Control   no-cache
  </code></pre>
  
  <p>I'm really losing all hope here and IE is making my go crazy (damn you Microsoft :D ), so any help or advice is much appriciated.</p>
  
  <p>EDIT: From more reasearch I found out that WebAPI requires a content-type to work and XDomainRequest doesnt send out one. So the only solution I see is too tweak my webapi to have a default content-type when nothing is set. Don't know how to this yet though</p>
  
  <p>EDIT2: Hacked my way through temporarily by transforming all my POSTs, to GETs, dont know how smart is this, but I see no bigger problem with it now, so it will do until I fix the problem</p>