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

    <legend id='EMV06'><style id='EMV06'><dir id='EMV06'><q id='EMV06'></q></dir></style></legend>
      <bdo id='EMV06'></bdo><ul id='EMV06'></ul>

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

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

        發布到外部 API 會引發 CORS,但它適用于 Postman

        POSTing to external API throws CORS but it works from Postman(發布到外部 API 會引發 CORS,但它適用于 Postman)
            <tbody id='syhrn'></tbody>

            <legend id='syhrn'><style id='syhrn'><dir id='syhrn'><q id='syhrn'></q></dir></style></legend>
            • <bdo id='syhrn'></bdo><ul id='syhrn'></ul>

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

              2. <tfoot id='syhrn'></tfoot>

                  本文介紹了發布到外部 API 會引發 CORS,但它適用于 Postman的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在使用 imgur api 上傳圖片 通過一個節點 js 應用程序.

                  I am using the imgur api to upload images via a node js app.

                  我正在將圖像轉換為 base64 字符串并通過 Postman 發送它們效果很好.

                  I am converting images to base64 strings and sending them via Postman works great.

                  我使用 node-fetch 進行 api 調用.

                  I use node-fetch to make api calls.

                  const fetch = require('node-fetch')
                  ...
                  async uploadImage(base64image) {
                          try {
                              const url = 'https://api.imgur.com/3/image'
                              const res = await fetch(url,
                                  {
                                      method: 'POST',
                                      body: { image: base64image },
                                      headers: {
                                          'content-type': 'application/json',
                                          'Authorization': 'Client-ID [my-client-id]',
                                          'Access-Control-Allow-Headers': 'Content-Type, Authorization, Access-Control-Allow-Headers',
                                          'Access-Control-Allow-Methods': 'POST',
                                      }
                                  }
                              )
                  
                              console.log(res)
                          } catch(err) {
                              console.log(err)
                          }
                      }
                  

                  錯誤:訪問 'https://api.imgur.com/3/image' 從源獲取'http://localhost:3000' 已被 CORS 策略阻止:請求標頭字段 Access-Control-Allow-Access-Control-Allow-Headers 在預檢響應中不允許使用標頭.

                  Error: Access to fetch at 'https://api.imgur.com/3/image' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers in preflight response.

                  我嘗試了許多Access-Control-Allow-xxx"標頭,但沒有一個有效..

                  I have tried many 'Access-Control-Allow-xxx' headers but none of them worked..

                  我認為它一定是我缺少的一些簡單的東西.我已經堅持了幾個小時,請幫助我.

                  I assume it must be something simple that I am missing. I have been stuck on this for hours please help me.

                  推薦答案

                  瀏覽器限制 HTTP 請求與你的網頁在同一個域,所以你將無法直接從瀏覽器訪問 imgur api 而不會遇到CORS 問題.

                  Browser restricts HTTP requests to be at the same domain as your web page, so you won't be able to hit imgur api directly from the browser without running into CORS issue.

                  我正在將圖像轉換為 base64 字符串并通過 Postman 發送它們效果很好.

                  I am converting images to base64 strings and sending them via Postman works great.

                  那是因為 Postman 不是瀏覽器,所以不受 CORS 政策的限制.

                  That's because Postman is not a browser, so is not limited by CORS policy.

                  我嘗試了許多Access-Control-Allow-xxx"標頭,但沒有一個工作..

                  I have tried many 'Access-Control-Allow-xxx' headers but none of them worked..

                  這些標頭必須由服務器作為響應返回 - 在您的情況下由 imgur 服務器返回.你不能在瀏覽器的請求中設置它們,所以它永遠不會起作用.

                  These headers must be returned by the server in response - in your case by the imgur server. You can't set them in the request from browser, so it'll never work.

                  錯誤:訪問 'https://api.imgur.com/3/image' 來自原點'http://localhost:3000' 已被 CORS 策略阻止:請求標頭字段 Access-Control-Allow-Headers 不允許預檢響應中的 Access-Control-Allow-Headers.

                  Error: Access to fetch at 'https://api.imgur.com/3/image' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers in preflight response.

                  您的問題的可能解決方案:

                  Possible solutions to your problem:

                  1. 如果您可以訪問后端 api,您可以在服務器上設置Access-Control-Allow-Origin"標頭并讓您的應用訪問該 api - 但因為您無法訪問 imgur服務器 - 你可能做不到.

                  1. If you have access to the backend api you can set the "Access-Control-Allow-Origin" header on the server and let your app access the api - but as you won't have access to the imgur server - you probably can't do that.

                  在瀏覽器中禁用 CORS - 您可以使用如下插件:https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=zh-CN.這種解決方法應該適合開發.該插件將禁用您的 CORS 設置,您將能夠點擊 imgur apis.

                  Disable CORS in the browser - you can use a plugin like: https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi?hl=en. This workaound should be fine for development. The plugin will disable your CORS settings and you will be able to hit imgur apis.

                  第三種解決方案是使用代理.您可以使用 express 設置小型節點服務器.然后,您將訪問您自己的節點服務器,該節點服務器又將訪問 imgur api.由于節點服務器不是瀏覽器環境,它不會有任何 CORS 問題,您將能夠以這種方式訪問?? imgur API.這也是您能夠毫無問題地從 Postman 訪問 API 的原因.由于 Postman 不是瀏覽器環境,因此不受 CORS 政策的限制.

                  The third solution is using a proxy. You can setup a small node server using express. You will then hit your own node server, which in turn will hit the imgur api. As node server is not a browser environment, it won't have any CORS issue and you will be able to access imgur API that way. This is also the reason you were able to hit the API from Postman without any issues. As Postman is not a browser environment, it's not limited by CORS policy.

                  這篇關于發布到外部 API 會引發 CORS,但它適用于 Postman的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  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屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                  Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)

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

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

                        <tfoot id='McNVB'></tfoot>
                            <tbody id='McNVB'></tbody>

                        • <i id='McNVB'><tr id='McNVB'><dt id='McNVB'><q id='McNVB'><span id='McNVB'><b id='McNVB'><form id='McNVB'><ins id='McNVB'></ins><ul id='McNVB'></ul><sub id='McNVB'></sub></form><legend id='McNVB'></legend><bdo id='McNVB'><pre id='McNVB'><center id='McNVB'></center></pre></bdo></b><th id='McNVB'></th></span></q></dt></tr></i><div class="xfrlbfd" id='McNVB'><tfoot id='McNVB'></tfoot><dl id='McNVB'><fieldset id='McNVB'></fieldset></dl></div>
                            <bdo id='McNVB'></bdo><ul id='McNVB'></ul>
                          • 主站蜘蛛池模板: 玻璃钢型材-玻璃钢风管-玻璃钢管道,生产厂家-[江苏欧升玻璃钢制造有限公司] | 海尔生物医疗四川代理商,海尔低温冰箱四川销售-成都壹科医疗器械有限公司 | 粘弹体防腐胶带,聚丙烯防腐胶带-全民塑胶 | 工业机械三维动画制作 环保设备原理三维演示动画 自动化装配产线三维动画制作公司-南京燃动数字 聚合氯化铝_喷雾聚氯化铝_聚合氯化铝铁厂家_郑州亿升化工有限公司 | 物联网卡_物联网卡购买平台_移动物联网卡办理_移动联通电信流量卡通信模组采购平台? | 东莞动力锂电池保护板_BMS智能软件保护板_锂电池主动均衡保护板-东莞市倡芯电子科技有限公司 | 岸电电源-60HZ变频电源-大功率变频电源-济南诚雅电子科技有限公司 | 上海洗地机-洗地机厂家-全自动洗地机-手推式洗地机-上海滢皓洗地机 | 玻纤土工格栅_钢塑格栅_PP焊接_单双向塑料土工格栅_复合防裂布厂家_山东大庚工程材料科技有限公司 | 双工位钻铣攻牙机-转换工作台钻攻中心-钻铣攻牙机一体机-浙江利硕自动化设备有限公司 | 二手光谱仪维修-德国OBLF光谱仪|进口斯派克光谱仪-热电ARL光谱仪-意大利GNR光谱仪-永晖检测 | 安平县鑫川金属丝网制品有限公司,声屏障,高速声屏障,百叶孔声屏障,大弧形声屏障,凹凸穿孔声屏障,铁路声屏障,顶部弧形声屏障,玻璃钢吸音板 | 磁力去毛刺机_去毛刺磁力抛光机_磁力光饰机_磁力滚抛机_精密金属零件去毛刺机厂家-冠古科技 | 天津试验仪器-电液伺服万能材料试验机,恒温恒湿标准养护箱,水泥恒应力压力试验机-天津鑫高伟业科技有限公司 | pH污水传感器电极,溶解氧电极传感器-上海科蓝仪表科技有限公司 | 包装机_厂家_价格-山东包装机有限公司| 高考志愿规划师_高考规划师_高考培训师_高报师_升学规划师_高考志愿规划师培训认证机构「向阳生涯」 | 半容积式换热器_北京浮动盘管换热器厂家|北京亿丰上达 | 并离网逆变器_高频UPS电源定制_户用储能光伏逆变器厂家-深圳市索克新能源 | 天津市能谱科技有限公司-专业的红外光谱仪_红外测油仪_紫外测油仪_红外制样附件_傅里叶红外光谱技术生产服务厂商 | 闭端端子|弹簧螺式接线头|防水接线头|插线式接线头|端子台|电源线扣+护线套|印刷电路板型端子台|金笔电子代理商-上海拓胜电气有限公司 | 礼仪庆典公司,礼仪策划公司,庆典公司,演出公司,演艺公司,年会酒会,生日寿宴,动工仪式,开工仪式,奠基典礼,商务会议,竣工落成,乔迁揭牌,签约启动-东莞市开门红文化传媒有限公司 | 中开泵,中开泵厂家,双吸中开泵-山东博二泵业有限公司 | 不锈钢闸阀_球阀_蝶阀_止回阀_调节阀_截止阀-可拉伐阀门(上海)有限公司 | 福建成考网-福建成人高考网 | 智能案卷柜_卷宗柜_钥匙柜_文件流转柜_装备柜_浙江福源智能科技有限公司 | 低粘度纤维素|混凝土灌浆料|有机硅憎水粉|聚羧酸减水剂-南京斯泰宝 | 万烁建筑设计院-建筑设计公司加盟,设计院加盟分公司,市政设计加盟 | 杭州可当科技有限公司—流量卡_随身WiFi_AI摄像头一站式解决方案 | 超声波乳化机-超声波分散机|仪-超声波萃取仪-超声波均质机-精浩机械|首页 | 软瓷_柔性面砖_软瓷砖_柔性石材_MCM软瓷厂家_湖北博悦佳软瓷 | 山东螺杆空压机,烟台空压机,烟台开山空压机-烟台开山机电设备有限公司 | 德国BOSCH电磁阀-德国HERION电磁阀-JOUCOMATIC电磁阀|乾拓百科 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛调查出轨取证公司_青岛婚外情取证-青岛探真调查事务所 | 净化板-洁净板-净化板价格-净化板生产厂家-山东鸿星新材料科技股份有限公司 | 真空干燥烘箱_鼓风干燥箱 _高低温恒温恒湿试验箱_光照二氧化碳恒温培养箱-上海航佩仪器 | 衬氟止回阀_衬氟闸阀_衬氟三通球阀_衬四氟阀门_衬氟阀门厂-浙江利尔多阀门有限公司 | 沈阳楼承板_彩钢板_压型钢板厂家-辽宁中盛绿建钢品股份有限公司 轴承振动测量仪电箱-轴承测振动仪器-测试仪厂家-杭州居易电气 | 万博士范文网-您身边的范文参考网站Vanbs.com | 一氧化氮泄露报警器,二甲苯浓度超标报警器-郑州汇瑞埔电子技术有限公司 | 双段式高压鼓风机-雕刻机用真空泵-绍兴天晨机械有限公司 |