Javascript 当输入浏览器的url返回预期数据时,fetch()返回不透明

Javascript 当输入浏览器的url返回预期数据时,fetch()返回不透明,javascript,cors,fetch,Javascript,Cors,Fetch,我有一个react应用程序,它可以获取我编写的WebAPI。这是WebAPI的url: http://ec2-54-70-8-113.us-west-2.compute.amazonaws.com/api/homepage 当我在浏览器中输入webAPI的url时,我得到以下信息: <ArrayOfHomepage xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.

我有一个react应用程序,它可以获取我编写的WebAPI。这是WebAPI的url:

http://ec2-54-70-8-113.us-west-2.compute.amazonaws.com/api/homepage
当我在浏览器中输入webAPI的url时,我得到以下信息:

<ArrayOfHomepage xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WebAPI">
    <Homepage>
        <product_description>
            This application will allow the user to use his/her device camera to scan a product barcode and look up the value of the prodcut on Amazon and eBay based on the products barcode
        </product_description>
        <product_title>What's my crap worth</product_title>
        <return_code>1 - successful read from database</return_code>
    </Homepage>
</ArrayOfHomepage>
这就是返回的结果:

Data:
Response {type: "opaque", url: "", redirected: false, status: 0, ok: false, …}
不是我所期望的。当我从fetch中删除{mode:“no cors”}参数时,我得到以下错误:

No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:8080' is therefore not allowed access. 
If an opaque response serves your needs, set the request's mode to 'no-cors'
to fetch the resource with CORS disabled.
关于如何使用fetch正确检索数据,有什么建议吗


谢谢你的建议和建议。

。然后(response=>response)
什么都不做。。你是说
.then(response=>response.text())
?如果亚马逊资源不允许cors请求,那么你将无法从浏览器中获取它们。。您需要一个代理服务器来获取该数据。最后一个问题。。。为什么要在客户端上获取XML数据??你打算怎么办呢?另外,
fetch
不是一个react,它是浏览器API的一部分。我可以通过在浏览器url框中键入WebAPI的地址并点击return,从WebAPI获取数据。我还可以在Postman中输入url,Pastman可以检索数据。因此,我认为我应该能够使用fetch()返回相同的数据。我只是在学习,所以请原谅我混淆了我的术语。此过程的最终结果是能够从WebAPI检索数据并将其显示在移动设备上。浏览器正确地告诉您,您无法从该域接收数据,因为响应未包含允许跨源访问所需的标头。因此,如果您要控制该服务器,则需要确保正确设置cors头以允许从其他域进行访问。另见。
No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:8080' is therefore not allowed access. 
If an opaque response serves your needs, set the request's mode to 'no-cors'
to fetch the resource with CORS disabled.