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

<i id='10WBX'><tr id='10WBX'><dt id='10WBX'><q id='10WBX'><span id='10WBX'><b id='10WBX'><form id='10WBX'><ins id='10WBX'></ins><ul id='10WBX'></ul><sub id='10WBX'></sub></form><legend id='10WBX'></legend><bdo id='10WBX'><pre id='10WBX'><center id='10WBX'></center></pre></bdo></b><th id='10WBX'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='10WBX'><tfoot id='10WBX'></tfoot><dl id='10WBX'><fieldset id='10WBX'></fieldset></dl></div>

    <small id='10WBX'></small><noframes id='10WBX'>

    1. <tfoot id='10WBX'></tfoot>

          <bdo id='10WBX'></bdo><ul id='10WBX'></ul>

        <legend id='10WBX'><style id='10WBX'><dir id='10WBX'><q id='10WBX'></q></dir></style></legend>
      1. 向 https://newsapi.org 發出請求時,CORS 政策出現問題

        Problem with CORS policy, when making a request to https://newsapi.org(向 https://newsapi.org 發出請求時,CORS 政策出現問題)
      2. <i id='64W7i'><tr id='64W7i'><dt id='64W7i'><q id='64W7i'><span id='64W7i'><b id='64W7i'><form id='64W7i'><ins id='64W7i'></ins><ul id='64W7i'></ul><sub id='64W7i'></sub></form><legend id='64W7i'></legend><bdo id='64W7i'><pre id='64W7i'><center id='64W7i'></center></pre></bdo></b><th id='64W7i'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='64W7i'><tfoot id='64W7i'></tfoot><dl id='64W7i'><fieldset id='64W7i'></fieldset></dl></div>

                <tbody id='64W7i'></tbody>

              <legend id='64W7i'><style id='64W7i'><dir id='64W7i'><q id='64W7i'></q></dir></style></legend>
              <tfoot id='64W7i'></tfoot>
                <bdo id='64W7i'></bdo><ul id='64W7i'></ul>

                <small id='64W7i'></small><noframes id='64W7i'>

                • 本文介紹了向 https://newsapi.org 發出請求時,CORS 政策出現問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我一直在我的網站上運行新聞 api 并通過將文件拖到網絡瀏覽器中在我的計算機上進行測試,網址會顯示為 file:///C:.然后我會將任何更改上傳到我的 GitHub 存儲庫并在 Github 頁面 https://name.github.io/repository/ 上運行它.

                  I have been running news api on my website and testing in on my computer by dragging the file into the web browser, the url would show up like that file:///C:. Then I would upload any changes to my GitHub repository and run it on Github pages https://name.github.io/repository/.

                  長期以來一切正常,但最終,API 停止工作,控制臺中出現錯誤 Access to fetch at 'https://newsapi.org/v2/everything?xx' from originhttps://name.github.io"已被 CORS 策略阻止:請求的資源上不存在Access-Control-Allow-Origin"標頭.如果不透明的響應滿足您的需求,請將請求的模式設置為no-cors"以獲取禁用 CORS 的資源.

                  Everything was working fine for a long time, but eventually, the API stopped working and error showed up in the console Access to fetch at 'https://newsapi.org/v2/everything?xx' from origin 'https://name.github.io' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

                  我嘗試將 mode: 'no-cors' 添加到 fetch 中,但它不適用于 return response.json();

                  I have tried to add mode: 'no-cors' to the fetch, but it didn't work with return response.json();

                  我的函數如下所示:

                    const url = 'https://newsapi.org/v2/everything?' +
                      'qInTitle=""&' +
                      `from=` +
                      'language=en&' +
                      'apiKey=';
                    const req = new Request(url);
                  
                    fetch(req).then(function(response) {
                      return response.json();
                    }).then(function(news) {
                      newsLoop(news);
                    });
                  

                  當我在本地運行它時,API 也停止工作 file:///C:,它顯示與 Github 頁面上的錯誤類似的錯誤 Access to fetch at 'https://newsapi.org/v2/everything?xx' from origin 'null' 已被 CORS 策略阻止:請求的資源上不存在Access-Control-Allow-Origin"標頭.如果不透明的響應滿足您的需求,請將請求的模式設置為no-cors"以獲取禁用 CORS 的資源.

                  The API stopped working also when I run it locally file:///C:, it displays a similar error to the one on Github pages Access to fetch at 'https://newsapi.org/v2/everything?xx' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

                  我該如何處理,以便 API 會在 Github 頁面上顯示信息,以及當我在我的電腦上本地運行它時?

                  How I can deal with it, so the API would display information on Github pages and when I run it locally on my pc?

                  推薦答案

                  你需要一個 CORS 代理

                  You need a CORS proxy

                  const proxyUrl = "https://cors-anywhere.herokuapp.com/"
                  const qInTitle = "";
                  const from = "";
                  const apiKey = "";
                  const url = `${proxyUrl}https://newsapi.org/v2/everything?qInTitle=${qInTitle}&from=${from}language=en&apiKey=${apiKey}`;
                  const request = new Request(url);
                  
                  fetch(request)
                    .then(response => response.json())
                    .then((news) => {
                      console.log(news);
                    })
                    .catch(error => {
                      console.log(error);
                    });

                  這篇關于向 https://newsapi.org 發出請求時,CORS 政策出現問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                    <bdo id='bIgnY'></bdo><ul id='bIgnY'></ul>

                      <tfoot id='bIgnY'></tfoot>

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

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

                          • 主站蜘蛛池模板: 免费激情 | 精品成人一区二区 | 午夜影院在线观看版 | 粉嫩一区二区三区四区公司1 | 久草视频2| 97久久精品午夜一区二区 | cao在线| 久久久久久久一级 | 在线资源视频 | 国产精品伦一区二区三级视频 | 日韩性在线| 成人在线免费 | 久久久久一区二区三区四区 | 欧美一区二区三区大片 | 羞羞的视频在线看 | 国产精品免费一区二区三区 | 精品成人av | 欧美日韩精品在线免费观看 | 日韩精品一区二区三区中文在线 | 久久精品国产免费 | 国产一区二区自拍 | 成人高清视频在线观看 | 亚洲欧美网| 国产免费一区二区 | 亚洲成人免费在线 | 一区二区三区视频在线 | 中文字幕成人网 | 香蕉久久av| 亚洲国产精品一区二区三区 | 天堂中文在线播放 | 成年网站在线观看 | av手机在线看| 伊人精品一区二区三区 | 午夜精品一区二区三区在线观看 | 亚洲欧美日韩在线一区二区 | 日韩中文字幕在线观看 | 国产精品69av | 成人av一区二区三区 | 久久亚洲一区二区三区四区 | 在线看免费的a | 欧美爱爱视频 |