我已經開始構建一個 Vue.js網站,將 AWS 放大版用于后端。在其中一個頁面中,我需要訪問外部URL地址,從中獲取響應,并查看對用戶的響應。重要的是要說URL沒有鏈接到我的網站,它與我無關。它完全是外部的,超出了我的控制范圍。我已經嘗試多次訪問該網址,使用許多方法,但到目前為止,每次嘗試訪問該網址時,我都會收到以下錯誤消息::8080/#/myPage:1 Access to XMLHttpRequest at 'https://~URL~?~DATA~' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js?b50d:178 GET https://~URL~?~DATA~ net::ERR_FAILED(我將實際網址替換為 ,并將文件名替換為 )。https://~URL~?~DATA~myPage當我嘗試打印從函數收到的錯誤時。我收到以下消息:myPage.vue?3266:161 Error: Network Error
at createError (createError.js?2d83:16)
at XMLHttpRequest.handleError (xhr.js?b50d:83)當我嘗試使用瀏覽器(谷歌瀏覽器)訪問網址時,它運行良好,沒有任何問題。它沒有要求我進行任何類型的身份驗證或類似的東西。我也用郵遞員嘗試過,它工作得很好。我只在使用我的 Vue.js 網站時才遇到此問題。當我從主機運行網站時,當我在主機上運行網站時(對無服務器網站使用 AWS Amplify 托管 - S3 存儲桶),就會發生此問題。當網站無法在本地主機上運行時,我仍然收到相同的錯誤消息。localhost以下是我嘗試訪問URL的一些方法:阿克西奧斯var config = { method: 'get', url: 'https://~URL~?~DATA~', headers: { 'Access-Control-Allow-Credentials': true }};axios(config).then(function (response) { console.log(response);}).catch(function (error) { console.log(error);});獲取var requestOptions = { method: 'GET', redirect: 'follow'};fetch("https://~URL~?~DATA~", requestOptions).then(response => response.text()).then(result => console.log(result)).catch(error => console.log('error', error));斷續器var xhr = new XMLHttpRequest();xhr.withCredentials = true;xhr.addEventListener("readystatechange", function() { if(this.readyState === 4) { console.log(this.responseText); }});xhr.open("GET", "https://~URL~?~DATA~");xhr.send();請求var request = require('request');var options = { 'method': 'GET', 'url': 'https://~URL~?~DATA~', 'headers': { }};request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body);});我真的需要你的幫助,因為到目前為止,我無法在網絡上找到任何解決方案。
無法使用 XML 向網址發送請求
至尊寶的傳說
2022-09-29 15:41:04