简体   繁体   English

谁能告诉我如何从此$ http标头中删除预检请求

[英]can any one tell me how can i remove preflight request from this $http header

    //individual logins
    $rootScope.setting.instances.forEach(function(ins) {

        var header = { 
                    "Accept": "application/json",
                    "Authorization": "Basic " + btoa( ins.uname + ':' + ins.pword ),
                    "Access-Control-Allow-Origin" : "*",
                    "Access-Control-Allow-Methods" : "GET, POST, DELETE, PUT, JSONP"

                };      

         $http({ method : 'post', url : ins.url, headers: header })
         .success( function( data )
         {
            console.log( ins.name +" login success" );
            $("#fail" + ins.id ).hide();
            $("#succ" + ins.id ).show();
            //logins : a global variable declared in app.js
            logins.push('{"ins" : '+ ins.id + ',"isAvailable" : "true"}');
            checkFinished();
         })
         .error( function( data)
         {
            console.log( ins.name +" login failed" );
            $("#fail" + ins.id ).show();
            $("#succ" + ins.id ).hide();
            //logins : a global variable declared in app.js
            logins.push('{"ins" : '+ ins.id + ',"isAvailable" : "false"}');
            checkFinished();
         });
    });
}

The CORS specification requires a browser to preflight the request with the OPTIONS request if any custom headers are specified on the cross origin request. 如果在跨源请求上指定了任何自定义标头,则CORS规范要求浏览器将请求与OPTIONS请求一起进行预检。 And, when it does the OPTIONS preflight, it does not include your custom headers because part of what the OPTIONS request is for is to find out what custom headers are allowed to be sent on the request. 而且,当它执行OPTIONS预检时,它不包括您的自定义标头,因为OPTIONS请求的目的是找出允许在请求上发送哪些自定义标头。 So, a server is not supposed to require custom headers on the OPTIONS request if it wants this to work from a browser. 因此,如果服务器希望它可以通过浏览器运行,则不应在OPTIONS请求上要求自定义标头。

So, if you don't want it to preflight with the OPTIONS request, then you have to not use custom headers on the request. 因此,如果您不希望它与OPTIONS请求一起进行预检,则不必在请求中使用自定义标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 谁能告诉我代码中发生了什么? - Can any one tell me what is happening in the code? 谁能告诉我代码有什么问题 - can any one tell me whats the wrong with code 谁能告诉我如何在节点 js 中使用 Facebook 策略进行 oauth? - Can any one tell me how to use facebook strategy for oauth in node js? 谁能告诉我如何仅使用 sort() 然后切换 case() 来对 javascript 中的时间进行排序 - Can any one tell me that how to sort time in javascript by using only sort() and then switch case() 谁能告诉我如何找到“使用二维码”按钮的 xpath - can any one tell me how to find xpath for "Use QR Code" button 如何将自定义标头添加到HTTP请求(Jquery)? - How can I add a custom header to a HTTP request (Jquery)? 如何为每个http请求添加一个Authorization标头? - How can I add an Authorization header to every http request? 如何使用 request npm 模块判断 http 请求是否完成? - How can I tell if http request is complete using the request npm module? 有人可以告诉我如何删除或隐藏此 JavaScript 代码吗? - Can someone please tell me how to remove or hide this JavaScript code? 如何在 JavaScript 中提取自定义 HTTP POST 请求 header 以便在另一个 POST 请求中传输? - How can I extract a custom HTTP POST request header in JavaScript for it to be transmitted in another POST request?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM