1. <i id='9lSf6'><tr id='9lSf6'><dt id='9lSf6'><q id='9lSf6'><span id='9lSf6'><b id='9lSf6'><form id='9lSf6'><ins id='9lSf6'></ins><ul id='9lSf6'></ul><sub id='9lSf6'></sub></form><legend id='9lSf6'></legend><bdo id='9lSf6'><pre id='9lSf6'><center id='9lSf6'></center></pre></bdo></b><th id='9lSf6'></th></span></q></dt></tr></i><div id='9lSf6'><tfoot id='9lSf6'></tfoot><dl id='9lSf6'><fieldset id='9lSf6'></fieldset></dl></div>

    <legend id='9lSf6'><style id='9lSf6'><dir id='9lSf6'><q id='9lSf6'></q></dir></style></legend>

    <small id='9lSf6'></small><noframes id='9lSf6'>

  2. <tfoot id='9lSf6'></tfoot>
      • <bdo id='9lSf6'></bdo><ul id='9lSf6'></ul>
    1. 拒绝设置不安全的标头“Origin"使用谷歌浏览

      时间:2023-10-14
        <tbody id='LH7D3'></tbody>

        <legend id='LH7D3'><style id='LH7D3'><dir id='LH7D3'><q id='LH7D3'></q></dir></style></legend>

        • <bdo id='LH7D3'></bdo><ul id='LH7D3'></ul>
            • <tfoot id='LH7D3'></tfoot>

              <i id='LH7D3'><tr id='LH7D3'><dt id='LH7D3'><q id='LH7D3'><span id='LH7D3'><b id='LH7D3'><form id='LH7D3'><ins id='LH7D3'></ins><ul id='LH7D3'></ul><sub id='LH7D3'></sub></form><legend id='LH7D3'></legend><bdo id='LH7D3'><pre id='LH7D3'><center id='LH7D3'></center></pre></bdo></b><th id='LH7D3'></th></span></q></dt></tr></i><div id='LH7D3'><tfoot id='LH7D3'></tfoot><dl id='LH7D3'><fieldset id='LH7D3'></fieldset></dl></div>
            • <small id='LH7D3'></small><noframes id='LH7D3'>

                本文介绍了拒绝设置不安全的标头“Origin"使用谷歌浏览器的 xmlHttpRequest 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                收到此错误消息:拒绝设置不安全的标头Origin"

                使用此代码:

                   function getResponse() {
                            document.getElementById("_receivedMsgLabel").innerHTML += "getResponse() called.<br/>";
                            if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
                                receiveReq.open("GET", "http://L45723:1802", true, "server", "server123");  //must use L45723:1802 at work.
                                receiveReq.onreadystatechange = handleReceiveMessage;
                                receiveReq.setRequestHeader("Origin", "http://localhost/");
                                receiveReq.setRequestHeader("Access-Control-Request-Origin", "http://localhost");
                                receiveReq.timeout = 0;
                                var currentDate = new Date();
                                var sendMessage = JSON.stringify({
                                    SendTimestamp: currentDate,
                                    Message: "Message 1",
                                    Browser: navigator.appName
                                });
                                receiveReq.send(sendMessage);
                
                            }
                        }
                

                我做错了什么?为了使这个 CORS 请求正常工作,我在标头中遗漏了什么?

                What am I doing wrong? What am I missing in the header to make this CORS request work?

                我尝试删除 receiveReq.setRequestHeader("Origin", ...) 调用,但 Google Chrome 在我的 receiveReq.open() 调用中引发访问错误...

                I tried removing the receiveReq.setRequestHeader("Origin", ...) call but then Google Chrome throws an access error on my receiveReq.open() call...

                为什么?

                推荐答案

                这只是一个猜测,因为我使用 jquery 处理 ajax 请求,包括 CORS.

                This is just a guess, as I use jquery for ajax requests, including CORS.

                我认为浏览器应该设置标题,而不是你.如果您能够设置标题,那将破坏安全功能的目的.

                I think the browser is supposed to set the header, not you. If you were able to set the header, that would defeat the purpose of the security feature.

                在不设置这些标头的情况下尝试请求,看看浏览器是否为您设置了它们.

                Try the request without setting those headers and see if the browser sets them for you.

                这篇关于拒绝设置不安全的标头“Origin"使用谷歌浏览器的 xmlHttpRequest 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:为什么 Chrome 会取消 CORS OPTION 请求 下一篇:xmlhttprequest 和 set-cookie &amp;曲奇饼

                相关文章

                最新文章

                <tfoot id='9uUYs'></tfoot>
              • <small id='9uUYs'></small><noframes id='9uUYs'>

                <i id='9uUYs'><tr id='9uUYs'><dt id='9uUYs'><q id='9uUYs'><span id='9uUYs'><b id='9uUYs'><form id='9uUYs'><ins id='9uUYs'></ins><ul id='9uUYs'></ul><sub id='9uUYs'></sub></form><legend id='9uUYs'></legend><bdo id='9uUYs'><pre id='9uUYs'><center id='9uUYs'></center></pre></bdo></b><th id='9uUYs'></th></span></q></dt></tr></i><div id='9uUYs'><tfoot id='9uUYs'></tfoot><dl id='9uUYs'><fieldset id='9uUYs'></fieldset></dl></div>
                <legend id='9uUYs'><style id='9uUYs'><dir id='9uUYs'><q id='9uUYs'></q></dir></style></legend>

                • <bdo id='9uUYs'></bdo><ul id='9uUYs'></ul>