I'm performing a cross-domain POST using jQuery ajax to call an ASP.net 4.5 WebAPI site:
$.support.cors = true;
$.ajax("http://mydomain/WebApi/api/authentication/", { type: "post", data: json, contentType: "application/json" });
Here is my server method:
public class AuthenticationController : ApiController
{
// Login or logout the user.
// POST api/authentication with login or logout data object
public HttpResponseMessage Post(object data)
{
return ProcessAction(data);
}
}
I've set the headers on remote server:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST,GET, OPTIONS
When I execute the code, I get a 405 Method Not Allowed - The requested resource does not support http method 'GET'.
The method I am calling works fine if called from the same domain.
Additionally, if I remove the contentType: "application/json"
option, I get a 500 Server Error.
It appears the contentType option has something to do with the problem, but I am not sure.
Any suggestions or advice are greatly appreciated!
Thanks.