pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<tfoot id='hMWnk'></tfoot>

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

        當使用 mode: no-cors 請求時,瀏覽器沒有添加我在

        When using mode: no-cors for a request, browser isn’t adding request header I’ve set in my frontend code(當使用 mode: no-cors 請求時,瀏覽器沒有添加我在前端代碼中設(shè)置的請求標頭) - IT屋-程序員軟件開發(fā)技術(shù)

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

              <tfoot id='68K1Y'></tfoot>

              <legend id='68K1Y'><style id='68K1Y'><dir id='68K1Y'><q id='68K1Y'></q></dir></style></legend>
                <tbody id='68K1Y'></tbody>
                <bdo id='68K1Y'></bdo><ul id='68K1Y'></ul>
                1. 本文介紹了當使用 mode: no-cors 請求時,瀏覽器沒有添加我在前端代碼中設(shè)置的請求標頭的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  在我的 React 應(yīng)用程序中,我有以下 API POST 以允許用戶編輯他們的個人資料(名稱和圖像).

                  in my React app, I have the following API POST to allow the user to edit their profile (name and image).

                    static updateProfile(formData, user_id) {
                      const request = new Request(`http://localhost:4300/api/v1/profiles/${user_id}`, {
                        headers: new Headers({
                          'Authorization': getBearerToken()
                        }),
                        mode: 'no-cors',
                        method: "POST",
                        body: formData
                      });
                  
                      return fetch(request).then(response => {
                        return response.json();
                      }).catch(error => {
                        return error;
                      });
                    }
                  

                  上面的問題是帶有授權(quán)令牌的標頭沒有在 POST 中發(fā)送...

                  The problem with the above is the header with the Authorization token is not being sent in the POST...

                  如何在上面的 fetch 請求中獲取要發(fā)送的 Authorization 標頭?

                  How can I get the Authorization header to be send in the fetch request above?

                  僅供參考,對于非多部分表單,授權(quán)令牌已成功發(fā)送,如下所示:

                  FYI, for non-multipart forms, the authorization token is sent successfully like so:

                    static loadProfile(user_id) {
                      const request = new Request(`http://localhost:4300/api/v1/profiles/${user_id}`, {
                        headers: new Headers({
                          'Authorization': getBearerToken(),
                          'Accept'       : 'application/json',
                          'Content-Type' : 'application/json',
                        })
                      });
                  
                      return fetch(request).then(response => {
                        return response.json();
                      }).catch(error => {
                        return error;
                      });
                    }
                  

                  推薦答案

                  如果你設(shè)置了任何特殊的請求頭,你不能使用 no-cors 模式,因為使用它的效果之一request 是它告訴瀏覽器不允許您的前端 JavaScript 代碼設(shè)置除 CORS 安全列出的請求標頭.請參閱規(guī)范要求:

                  You can’t use no-cors mode if you set any special request headers, because one of effect of using it for a request is that it tells browsers to not allow your frontend JavaScript code to set any request headers other than CORS-safelisted request-headers. See the spec requirements:

                  要將 name/value 對附加到 Headers 對象 (headers),請運行以下步驟:

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

                  1. 否則,如果 guardrequest-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".

                  Authorization 不是 CORS-safelisted request-header,因此如果您使用 mode: 'no-cors' 請求,您的瀏覽器將不允許您設(shè)置.Content-Type: application/json 也一樣.

                  Authorization isn’t a CORS-safelisted request-header, so your browser won’t allow you to set if you use mode: 'no-cors'for a request. Same for Content-Type: application/json.

                  如果您嘗試使用 no-cors 模式的原因是為了避免在不使用時出現(xiàn)的其他問題,則解決方案是修復(fù)導(dǎo)致其他問題的根本原因.因為無論您試圖解決什么問題,mode: 'no-cors' 最終都不會成為解決方案.它只會產(chǎn)生不同的問題,比如你現(xiàn)在遇到的問題.

                  If the reason you’re trying to use no-cors mode is to avoid some other problem that occurs if you don’t use, the solution is to fix the underlying cause of that other problem. Because no matter what problem you might be trying to solve, mode: 'no-cors' isn’t going to turn out to be a solution in the end. It’s just going to create different problems like what you’re hitting now.

                  這篇關(guān)于當使用 mode: no-cors 請求時,瀏覽器沒有添加我在前端代碼中設(shè)置的請求標頭的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調(diào)用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內(nèi)容)
                  Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)
                  <tfoot id='LmlhN'></tfoot>
                        <tbody id='LmlhN'></tbody>

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

                          • <small id='LmlhN'></small><noframes id='LmlhN'>

                          • <legend id='LmlhN'><style id='LmlhN'><dir id='LmlhN'><q id='LmlhN'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 运动木地板价格,篮球馆体育运动木地板生产厂家_欧氏地板 | 变频器维修公司_plc维修_伺服驱动器维修_工控机维修 - 夫唯科技 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 轴流风机-鼓风机-离心风机-散热风扇-罩极电机,生产厂家-首肯电子 | 莱州网络公司|莱州网站建设|莱州网站优化|莱州阿里巴巴-莱州唯佳网络科技有限公司 | 固诺家居-全屋定制十大品牌_整体衣柜木门橱柜招商加盟 | 网带通过式抛丸机,,网带式打砂机,吊钩式,抛丸机,中山抛丸机生产厂家,江门抛丸机,佛山吊钩式,东莞抛丸机,中山市泰达自动化设备有限公司 | 机械立体车库租赁_立体停车设备出租_智能停车场厂家_春华起重 | CXB船用变压器-JCZ系列制动器-HH101船用铜质开关-上海永上船舶电器厂 | 膏剂灌装旋盖机-眼药水灌装生产线-西林瓶粉剂分装机-南通博琅机械科技 | 圆周直径尺-小孔内视镜-纤维研磨刷-东莞市高腾达精密工具 | 高楼航空障碍灯厂家哪家好_航空障碍灯厂家_广州北斗星障碍灯有限公司 | 氢氧化钙设备, 氢氧化钙生产线-淄博惠琛工贸有限公司 | 河南膏药贴牌-膏药代加工-膏药oem厂家-洛阳今世康医药科技有限公司 | 999范文网_优质范文下载写作帮手 | 查分易-成绩发送平台官网| 纯化水设备-纯水设备-超纯水设备-[大鹏水处理]纯水设备一站式服务商-东莞市大鹏水处理科技有限公司 | 真空泵厂家_真空泵机组_水环泵_旋片泵_罗茨泵_耐腐蚀防爆_中德制泵 | 氢氧化钙设备_厂家-淄博工贸有限公司 | 10吨无线拉力计-2吨拉力计价格-上海佳宜电子科技有限公司 | 根系分析仪,大米外观品质检测仪,考种仪,藻类鉴定计数仪,叶面积仪,菌落计数仪,抑菌圈测量仪,抗生素效价测定仪,植物表型仪,冠层分析仪-杭州万深检测仪器网 | 找果网 | 苹果手机找回方法,苹果iPhone手机丢了找回,认准找果网! | 华中线缆有限公司-电缆厂|电缆厂家|电线电缆厂家 | 硅胶管挤出机厂家_硅胶挤出机生产线_硅胶条挤出机_臣泽智能装备 贵州科比特-防雷公司厂家提供贵州防雷工程,防雷检测,防雷接地,防雷设备价格,防雷产品报价服务-贵州防雷检测公司 | 深圳市八百通智能技术有限公司官方网站 | 不发火防静电金属骨料_无机磨石_水泥自流平_修补砂浆厂家「圣威特」 | 热缩管切管机-超声波切带机-织带切带机-无纺布切布机-深圳市宸兴业科技有限公司 | 缝纫客| 喷播机厂家_二手喷播机租赁_水泥浆洒布机-河南青山绿水机电设备有限公司 | 不锈钢/气体/液体玻璃转子流量计(防腐,选型,规格)-常州天晟热工仪表有限公司【官网】 | 电液推杆生产厂家|电动推杆|液压推杆-扬州唯升机械有限公司 | 泰来华顿液氮罐,美国MVE液氮罐,自增压液氮罐,定制液氮生物容器,进口杜瓦瓶-上海京灿精密机械有限公司 | PU树脂_水性聚氨酯树脂_聚氨酯固化剂_聚氨酯树脂厂家_宝景化工 | 异噻唑啉酮-均三嗪-三丹油-1227-中北杀菌剂厂家 | 蜘蛛车-高空作业平台-升降机-高空作业车租赁-臂式伸缩臂叉装车-登高车出租厂家 - 普雷斯特机械设备(北京)有限公司 | 纸箱网 -纸箱机械|设备|包装纸盒|包装印刷行业门户网站 | 注浆压力变送器-高温熔体传感器-矿用压力传感器|ZHYQ朝辉 | 四川成人高考_四川成考报名网| 佛山市钱丰金属不锈钢蜂窝板定制厂家|不锈钢装饰线条|不锈钢屏风| 电梯装饰板|不锈钢蜂窝板不锈钢工艺板材厂家佛山市钱丰金属制品有限公司 | 纳米二氧化硅,白炭黑,阴离子乳化剂-臻丽拾科技 | 干粉砂浆设备-干粉砂浆生产线-干混-石膏-保温砂浆设备生产线-腻子粉设备厂家-国恒机械 |