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

    1. <small id='qRbAH'></small><noframes id='qRbAH'>

        <bdo id='qRbAH'></bdo><ul id='qRbAH'></ul>

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

        如何将基本身份验证标头分配给 XMLHTTPREQUEST?

        时间:2023-10-14
        <i id='PTahP'><tr id='PTahP'><dt id='PTahP'><q id='PTahP'><span id='PTahP'><b id='PTahP'><form id='PTahP'><ins id='PTahP'></ins><ul id='PTahP'></ul><sub id='PTahP'></sub></form><legend id='PTahP'></legend><bdo id='PTahP'><pre id='PTahP'><center id='PTahP'></center></pre></bdo></b><th id='PTahP'></th></span></q></dt></tr></i><div id='PTahP'><tfoot id='PTahP'></tfoot><dl id='PTahP'><fieldset id='PTahP'></fieldset></dl></div>

            <small id='PTahP'></small><noframes id='PTahP'>

            <legend id='PTahP'><style id='PTahP'><dir id='PTahP'><q id='PTahP'></q></dir></style></legend>
              <tbody id='PTahP'></tbody>

            <tfoot id='PTahP'></tfoot>
                <bdo id='PTahP'></bdo><ul id='PTahP'></ul>
                  本文介绍了如何将基本身份验证标头分配给 XMLHTTPREQUEST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我已经阅读了很多关于 preflight 和 CORS 的答案,所以请不要发布链接引用我应该阅读的内容.许多答案都是从服务器的角度来看的,但在这种情况下,我是客户.我是否设置了原始标头?我的假设是这是一个简单的请求,对吗?

                  I've read many answers of preflight and CORS so please do not post links referencing what I should read. Many of the answers are from a server-perspective, but I am the client in this case. Do I set the origin header? My assumption is that this is a simple request, am I right?

                   req.open("POST", url, true);
                   req.setRequestHeader( 'Content-Type',   'application/blahblah' );
                   req.setRequestHeader( 'Accept', 'application/blahblah' );
                   req.setRequestHeader("Authorization", "Basic " + btoa(user + ":" + pass)); 
                   req.send();
                  

                  但它仍然无法正常工作,我的错误:

                  Yet its still not working, my error:

                  对预检请求的响应未通过访问控制检查:请求的资源上不存在Access-Control-Allow-Origin"标头.因此,Origin 'null' 不允许访问.响应的 HTTP 状态代码为 500.

                  Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 500.

                  推荐答案

                  解决方案:

                  var req = new XMLHttpRequest();
                      req.setRequestHeader('Authorization', 'Basic [base64 encoded password here]' );
                  

                  这篇关于如何将基本身份验证标头分配给 XMLHTTPREQUEST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:XMLHttpRequest 的 onerror 处理程序应该何时触发 下一篇:循环内的 jQuery.ajax()

                  相关文章

                  最新文章

                1. <tfoot id='IG0By'></tfoot>
                  <legend id='IG0By'><style id='IG0By'><dir id='IG0By'><q id='IG0By'></q></dir></style></legend>
                  • <bdo id='IG0By'></bdo><ul id='IG0By'></ul>

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