CORS Java脚本调用与匿名一起工作,但与windows身份验证一起失败
我试图从JavaScript页面调用rest端点。如果在rest端点服务器上启用了匿名身份验证,并且我使用了类似于以下代码的GET,那么我会得到适当的响应:CORS Java脚本调用与匿名一起工作,但与windows身份验证一起失败,cors,Cors,我试图从JavaScript页面调用rest端点。如果在rest端点服务器上启用了匿名身份验证,并且我使用了类似于以下代码的GET,那么我会得到适当的响应: let path = 'https://RestendpointURL'; var xmlHttp = new XMLHttpRequest(); xmlHttp.open('GET', path, true ); xmlHttp.onreadystatechange = function
let path = 'https://RestendpointURL';
var xmlHttp = new XMLHttpRequest();
xmlHttp.open('GET', path, true );
xmlHttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
xmlHttp.send( null );
但是,出于明显的安全原因,我们禁用了匿名身份验证,服务器使用Windows身份验证。因此,我将代码更改为以下内容:
let path = 'https://restendpoindURL;
var xmlHttp = new XMLHttpRequest();
xmlHttp.open('POST', path, true );
xmlHttp.withCredentials = true;
xmlHttp.onreadystatechange = function() {
console.log(this.responseText);
console.log("this.responseText");
if (this.readyState == 4 && this.status == 200) {
alert(this.responseText);
}
};
xmlHttp.send( null );
}
在这一点上,我开始得到以下错误
访问位于“”的XMLHttpRequesthttps://RestendpointURL“起源”https://devmachine.domain'已被CORS策略阻止:当请求的凭据模式为'include'时,响应中的'Access Control Allow Origin'标头的值不得为通配符'*'。XMLHttpRequest启动的请求的凭据模式由withCredentials属性控制。
html:29 posthttps://RestendpointURL'net::ERR_失败
我还在我的chrome开发工具的网络选项卡上返回响应
它在响应标题中指出“访问控制允许来源:”
虽然那不是真的!我没有访问rest端点服务器代码的权限。但开发它的同事指出:
[使能CORS(来源:https://devmachine.domain,标头:,方法:“*”)已添加到控制器中
并在Global.asax文件“Application_BeginRequest()”方法中处理选项:
protected void Application_BeginRequest()
{
if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS")
{
Response.Headers.Add("Access-Control-Allow-Origin", "https://devmachine.domain");
Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type");
Response.Headers.Add("Access-Control-Allow-Methods", "GET, OPTIONS");
Response.Headers.Add("Access-Control-Allow-Credentials", "true");
Response.Flush();
}
}
知道我做错了什么吗?
提前谢谢