久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <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="qwawimqqmiuu" id='EMV06'><tfoot id='EMV06'></tfoot><dl id='EMV06'><fieldset id='EMV06'></fieldset></dl></div>

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

        POSTing to external API throws CORS but it works from Postman(發(fā)布到外部 API 會引發(fā) 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="qwawimqqmiuu" 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>

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

                  問題描述

                  我正在使用 imgur api 上傳圖片 通過一個節(jié)點 js 應(yīng)用程序.

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

                  我正在將圖像轉(zhuǎn)換為 base64 字符串并通過 Postman 發(fā)送它們效果很好.

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

                  我使用 node-fetch 進行 api 調(diào)用.

                  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 在預(yù)檢響應(yīng)中不允許使用標頭.

                  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..

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

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

                  推薦答案

                  瀏覽器限制 HTTP 請求與你的網(wǎng)頁在同一個域,所以你將無法直接從瀏覽器訪問 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.

                  我正在將圖像轉(zhuǎn)換為 base64 字符串并通過 Postman 發(fā)送它們效果很好.

                  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..

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

                  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 不允許預(yù)檢響應(yīng)中的 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,您可以在服務(wù)器上設(shè)置Access-Control-Allow-Origin"標頭并讓您的應(yīng)用訪問該 api - 但因為您無法訪問 imgur服務(wù)器 - 你可能做不到.

                  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.這種解決方法應(yīng)該適合開發(fā).該插件將禁用您的 CORS 設(shè)置,您將能夠點擊 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 設(shè)置小型節(jié)點服務(wù)器.然后,您將訪問您自己的節(jié)點服務(wù)器,該節(jié)點服務(wù)器又將訪問 imgur api.由于節(jié)點服務(wù)器不是瀏覽器環(huán)境,它不會有任何 CORS 問題,您將能夠以這種方式訪問?? imgur API.這也是您能夠毫無問題地從 Postman 訪問 API 的原因.由于 Postman 不是瀏覽器環(huán)境,因此不受 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.

                  這篇關(guān)于發(fā)布到外部 API 會引發(fā) CORS,但它適用于 Postman的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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() 的限制?)

                  <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="qwawimqqmiuu" id='McNVB'><tfoot id='McNVB'></tfoot><dl id='McNVB'><fieldset id='McNVB'></fieldset></dl></div>
                            <bdo id='McNVB'></bdo><ul id='McNVB'></ul>
                          • 主站蜘蛛池模板: 国产精品毛片久久久久久 | 国产欧美在线一区二区 | 久久久精品一区 | 久久精品国产久精国产 | 一呦二呦三呦国产精品 | 亚洲精品成人在线 | 欧美高清视频在线观看 | 国产日韩91| 国产欧美三区 | 中文在线视频观看 | 亚洲国产精品久久久久秋霞不卡 | 日韩一区二区三区在线视频 | 欧美男人亚洲天堂 | 综合久 | 日日操操 | 欧美v日韩v | 国产精品国产三级国产aⅴ浪潮 | 福利片在线观看 | 亚洲人成在线播放 | 成人在线观看中文字幕 | 成人av一区二区三区 | 91精品国产一区二区三区 | 日韩在线 | 成人亚洲精品久久久久软件 | 天堂网中文 | 五月天婷婷综合 | 国产一区二区三区免费观看视频 | 欧美日韩国产在线观看 | 亚洲高清在线 | 午夜影院在线观看免费 | 在线视频 中文字幕 | 美女在线一区二区 | 国产一区二区三区四区五区3d | 国产精品视频999 | 91精品国产91久久久久久不卞 | 美日韩中文字幕 | av网站免费观看 | 久久精品国产一区二区三区不卡 | 日韩一区二区视频 | 久久久国产一区 | 午夜天堂精品久久久久 |