Web Api 2与cors不工作,jquery没有发送预检?

时间:2014-05-02 06:46:02

标签: jquery asp.net-web-api

我在webapi的HttpConfiguration中有这个。

var cors = new EnableCorsAttribute("*", "*", "*","*");
configuration.EnableCors(cors);

我用以下方式提出要求:

$.ajax({
    type: 'POST', url: "http://www.remoteurl.com",
    crossDomain: true,
    data: JSON.stringify({
        category: 'test',
        id: 'test',
        version: 'test',
        payload: JSON.stringify({
        'options': {
            imageWidth: 7360,
            imageHeight: 4912,
            InternalCameraParameters: [11349, 0, 0, 0, 11341.35490, 0, 3655, 2456, 1],
            Roll: i.roll() * Math.PI / 180,
            Pitch: i.pitch() * Math.PI / 180,
            Yaw: i.heading() * Math.PI / 180,
            Height: i.height()
        }
    })
})
}).done((data: any[]) => {
    console.log(data);
});

但是在查看网络标签时,看起来邮件是唯一发送的请求。不是选项请求先发送。然后这个帖子就被取消了:

XMLHttpRequest cannot load http://www.remoteurl.com. No 'Access-`Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:19024' is therefore not allowed access.`

0 个答案:

没有答案