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

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

      2. 自定义标头未添加到请求对象

        时间:2023-10-02
          <bdo id='RfUP5'></bdo><ul id='RfUP5'></ul>
          <i id='RfUP5'><tr id='RfUP5'><dt id='RfUP5'><q id='RfUP5'><span id='RfUP5'><b id='RfUP5'><form id='RfUP5'><ins id='RfUP5'></ins><ul id='RfUP5'></ul><sub id='RfUP5'></sub></form><legend id='RfUP5'></legend><bdo id='RfUP5'><pre id='RfUP5'><center id='RfUP5'></center></pre></bdo></b><th id='RfUP5'></th></span></q></dt></tr></i><div id='RfUP5'><tfoot id='RfUP5'></tfoot><dl id='RfUP5'><fieldset id='RfUP5'></fieldset></dl></div>
              <tbody id='RfUP5'></tbody>
            <tfoot id='RfUP5'></tfoot>
              • <small id='RfUP5'></small><noframes id='RfUP5'>

                  <legend id='RfUP5'><style id='RfUP5'><dir id='RfUP5'><q id='RfUP5'></q></dir></style></legend>
                  本文介绍了自定义标头未添加到请求对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 fetch api.

                  I'm trying to use fetch api.

                  首先我创建一个 new Headers() 对象:

                  First i create a new Headers() object:

                  var oHeaders = new Headers({
                      'Accept': 'application/json',
                      'Content-Type': 'application/json',
                      "X-DocuSign-Authentication": '{"Username":"xxx","Password":"xxx","IntegratorKey":"xxx"}'
                  })
                  

                  如果我尝试记录标题,则在实例化标题后一切都正确.

                  After headers is instantiated if i try to log headers everything is correct.

                  oHeaders.forEach(function(v){console.log(v)})
                  //logs: 2 application/json {"Username":"xxx","Password":"xxx","IntegratorKey":"xxx"}
                  

                  我创建了 Request 对象:

                  the i create the Request object:

                  var oReq = new Request('https://eu.docusign.net/restapi/v2/login_information', {
                    method: 'GET',
                    headers: oHeaders,
                    mode: 'no-cors',
                  });
                  

                  如果我尝试记录请求对象的标头,则只有 accept 标头会在那里.

                  If i try to log the headers of the request object only the accept header will be there.

                  oReq.headers.forEach(function(v){console.log(v)})
                  //logs: application/json
                  

                  如果我尝试 fetch(oReq) 我得到 401 未授权 响应.

                  If i try to fetch(oReq) i get 401 unauthorized response.

                  是什么让标题消失了?

                  推荐答案

                  当您为请求设置 mode: 'no-cors' 时,浏览器将不允许您设置任何其他请求标头比 CORS-safelisted request-header.请参阅规范要求:

                  When you set mode: 'no-cors'for a request, browsers won’t allow you to set any request headers other than CORS-safelisted request-headers. See the spec requirements:

                  将名称/值 (name/value) 对附加到 Headers 对象 (headers),运行以下步骤:

                  To append a name/value (name/value) pair to a Headers object (headers), run these steps:

                  1. 否则,如果 guard 是 "request-no-cors" 并且 name/value 不是CORS-safelisted request-header,返回.
                  1. Otherwise, if guard is "request-no-cors" and name/value is not a CORS-safelisted request-header, return.

                  在该算法中,return 等同于在不将该标头添加到 Headers 对象的情况下返回".

                  In that algorithm, return equates to "return without adding that header to the Headers object".

                  这篇关于自定义标头未添加到请求对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:接收到 fetch POST 请求的响应后,如何将用户重定向到页面? 下一篇:这个特定的 ReactJs 代码如何执行初学者问题?

                  相关文章

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

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

                  2. <small id='NSTy3'></small><noframes id='NSTy3'>