POST请求因浏览器OPTIONS预检请求而失败

时间:2014-11-26 12:17:02

标签: ajax cors fiddler http-options-method

我的问题:
由于OPTIONS请求失败,浏览器不允许发送请求。

使用javascript发送的数据看起来像是:

var params = "grant_type=password&username=" + username + "&password=" + password;
        $http({
            url: '/Token',
            method: "POST",
            withCredentials: true,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
            data: params
        })


这是请求后从chrome控制台看起来的样子: enter image description here

注意
当我试图从提琴手发帖时,请求成功了。
但是,如果我试图从提琴手提出选项请求,它会像Chrome那样失败。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

许多提供商不允许使用此方法,因为它可能用于恶意目的。

引用规范:

This method allows the client to determine the options and/or requirements 
associated with a resource, or the capabilities of a server, without implying
a resource action or initiating a resource retrieval.

我看到很多黑客用这个选项探测服务器寻找漏洞。我将所有服务器和客户端服务器配置为返回 405 ERROR (不允许使用方法)。