OPTIONS方法未使用凭据请求401

时间:2018-07-12 02:58:52

标签: javascript asp.net-web-api vue.js fetch

我试图将一些获取的数据发布到API服务器。 该服务器是ASP.NET Web API,.NET Framework v4.5。在IIS上发布,仅启用Windows身份验证。

但是,帖子的预检的请求标头不包含cookie。因此出现了“ 401未经授权”错误。

我的获取请求代码和chrome的请求标头。

fetch(url,
{
    method: 'POST',
    mode: 'cors',
    headers: {
        'Accept': 'application/json, text/plain, */*',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify(loaItem),
    credentials: 'include'
})


OPTIONS /api/loasdup HTTP/1.1
Host: localhost:4501
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://localhost:8081
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, 
like Gecko) Chrome/67.0.3396.99 Safari/537.36
Access-Control-Request-Headers: content-type
Accept: */*
Referer: http://localhost:8081/loa/copy/LOA201807120000
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7

有什么想法吗?

IIS中的响应标头:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: *
Access-Control-Allow-Origin: http://localhost:8081

OPTIONS的请求和响应详细信息 The request and response details for OPTIONS

对GET的请求和响应正常运行 Tee request and response for GET

0 个答案:

没有答案