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>
                          • 主站蜘蛛池模板: 一体化污水处理设备-一体化净水设备-「山东梦之洁水处理」 | 天津拓展_天津团建_天津趣味运动会_天津活动策划公司-天津华天拓展培训中心 | 武汉宣传片制作-视频拍摄-企业宣传片公司-武汉红年影视 | 口臭的治疗方法,口臭怎么办,怎么除口臭,口臭的原因-口臭治疗网 | 舞台木地板厂家_体育运动木地板_室内篮球馆木地板_实木运动地板厂家_欧氏篮球地板推荐 | 注浆压力变送器-高温熔体传感器-矿用压力传感器|ZHYQ朝辉 | 裹包机|裹膜机|缠膜机|绕膜机-上海晏陵智能设备有限公司 | 云南丰泰挖掘机修理厂-挖掘机维修,翻新,再制造的大型企业-云南丰泰工程机械维修有限公司 | 回转支承-转盘轴承-回转驱动生产厂家-洛阳隆达轴承有限公司 | 净化工程_无尘车间_无尘车间装修-广州科凌净化工程有限公司 | 高温链条油|高温润滑脂|轴承润滑脂|机器人保养用油|干膜润滑剂-东莞卓越化学 | 半自动预灌装机,卡式瓶灌装机,注射器灌装机,给药器灌装机,大输液灌装机,西林瓶灌装机-长沙一星制药机械有限公司 | 扬州汇丰仪表有限公司| 防水套管厂家-柔性防水套管-不锈钢|刚性防水套管-天翔管道 | 伟秀电气有限公司-10kv高低压开关柜-高低压配电柜-中置柜-充气柜-欧式箱变-高压真空断路器厂家 | 浙江华锤电器有限公司_地磅称重设备_防作弊地磅_浙江地磅售后维修_无人值守扫码过磅系统_浙江源头地磅厂家_浙江工厂直营地磅 | 下水道疏通_管道疏通_马桶疏通_附近疏通电话- 立刻通 | 捷码低代码平台 - 3D数字孪生_大数据可视化开发平台「免费体验」 | 铝镁锰板厂家_进口钛锌板_铝镁锰波浪板_铝镁锰墙面板_铝镁锰屋面-杭州军晟金属建筑材料 | 定量包装秤,吨袋包装称,伸缩溜管,全自动包装秤,码垛机器人,无锡市邦尧机械工程有限公司 | 周口市风机厂,周鼓风机,河南省周口市风机厂 | 河南橡胶接头厂家,河南波纹补偿器厂家,河南可曲挠橡胶软连接,河南套筒补偿器厂家-河南正大阀门 | 聚氨酯催化剂K15,延迟催化剂SA-1,叔胺延迟催化剂,DBU,二甲基哌嗪,催化剂TMR-2,-聚氨酯催化剂生产厂家 | 卫生型双针压力表-高温防腐差压表-安徽康泰电气有限公司 | 黑龙江「京科脑康」医院-哈尔滨失眠医院_哈尔滨治疗抑郁症医院_哈尔滨精神心理医院 | 背压阀|减压器|不锈钢减压器|减压阀|卫生级背压阀|单向阀|背压阀厂家-上海沃原自控阀门有限公司 本安接线盒-本安电路用接线盒-本安分线盒-矿用电话接线盒-JHH生产厂家-宁波龙亿电子科技有限公司 | 科研ELISA试剂盒,酶联免疫检测试剂盒,昆虫_植物ELISA酶免试剂盒-上海仁捷生物科技有限公司 | 特种阀门-调节阀门-高温熔盐阀-镍合金截止阀-钛阀门-高温阀门-高性能蝶阀-蒙乃尔合金阀门-福建捷斯特阀门制造有限公司 | 工业胀紧套_万向节联轴器_链条-规格齐全-型号选购-非标订做-厂家批发价格-上海乙谛精密机械有限公司 | LNG鹤管_内浮盘价格,上装鹤管,装车撬厂家-连云港赛威特机械 | 抖音短视频运营_企业网站建设_网络推广_全网自媒体营销-东莞市凌天信息科技有限公司 | 通用磨耗试验机-QUV耐候试验机|久宏实业百科 | 广州/东莞小字符喷码机-热转印打码机-喷码机厂家-广州瑞润科技 | 慈溪麦田广告公司,提供慈溪广告设计。 | TPU薄膜_TPU薄膜生产厂家_TPU热熔胶膜厂家定制_鑫亘环保科技(深圳)有限公司 | 预制舱-电力集装箱预制舱-模块化预制舱生产厂家-腾达电器设备 | 彼得逊采泥器-定深式采泥器-电动土壤采样器-土壤样品风干机-常州索奥仪器制造有限公司 | 变频器维修公司_plc维修_伺服驱动器维修_工控机维修 - 夫唯科技 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 湖南长沙商标注册专利申请,长沙公司注册代理记账首选美创! | 过跨车_过跨电瓶车_过跨转运车_横移电动平车_厂区转运车_无轨转运车 | 南京PVC快速门厂家南京快速卷帘门_南京pvc快速门_世界500强企业国内供应商_南京美高门业 |