Ajax回调可以';找不到授权标头

Ajax回调可以';找不到授权标头,ajax,wcf,http-headers,xmlhttprequest,Ajax,Wcf,Http Headers,Xmlhttprequest,我尝试使用ajax(xmlHttpRequest)使用WCF服务(REST)。该服务需要基本身份验证 我的ajax调用是: var httpRequest = new XMLHttpRequest(); httpRequest.onreadystatechange = function () { if (httpRequest.readyState == 4) { if (httpRequest.status ==

我尝试使用ajax(xmlHttpRequest)使用WCF服务(REST)。该服务需要基本身份验证

我的ajax调用是:

 var httpRequest = new XMLHttpRequest();
         httpRequest.onreadystatechange = function () {
             if (httpRequest.readyState == 4) {
                 if (httpRequest.status == 200) {
                     //do some stuff
                 }
             }

         };
         httpRequest.open('PUT', 'http://localhost:59000/v1/users/1', true, 'user1', 'user1');
         httpRequest.withCredentials = "true";
         //must authenticate both..in open() but also set header manually ...cf http://stackoverflow.com/questions/1358550/xmlhttp-request-basic-authentication-issue
         httpRequest.setRequestHeader('Auhtorization', 'Basic user1:user1');
         httpRequest.setRequestHeader('Accept', 'application/json');
         // overridemimeType() does not set content type header .... don't know why ?
         httpRequest.setRequestHeader('Content-Type', 'application/json');
         var params = { "UserName": "user1" };
         var requestBodyString = JSON.stringify(params);
         httpRequest.send(requestBodyString);
我首先在服务器端处理请求的方式如下

        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin",
                      crossDomain);

        //preflight request : cf https://developer.mozilla.org/en/http_access_control 
        if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
        {
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods",
                          "GET, POST, PUT, DELETE");
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Credentials", "true");

            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept, DummyOneForTest");

            HttpContext.Current.Response.AddHeader("Access-Control-Max-Age",
                          "1728000");
            HttpContext.Current.Response.End();
        }
我的浏览器向我发送了一个错误“请求头字段AUHTORIZE不被访问控制允许头全部覆盖”,但正如您所看到的,它位于响应头中

此外,当我尝试与小提琴一切都很好,我甚至有头球虚拟一个允许

所以我真的很困惑,如果有人能帮忙,请帮忙


感谢

获得了它,当您在“使用visual studio开发服务器”上运行服务器时,尝试添加头(第二个代码块)时会引发异常:“此操作需要IIS集成管道模式”

解决方案位于“使用IIS web服务器”的应用程序配置中

因此,

您不能要求VisualStudio告诉您何时抛出异常,而我错过了它


谢谢

也许这与此无关,但上面的Ajax代码片段也将标题名称拼写为“Auhtorization”而不是“Authorization”。

你是对的,但它没有解决问题。无论如何谢谢你