【发布时间】:2019-07-17 07:21:37
【问题描述】:
在我的 react native 应用程序中,我试图对我的本地后端服务器执行fetch。在我的package.json 中,我已经输入了"proxy": "http://localhost:3000"。
我的抓取看起来像
fetch('/')
.then(response => response.json())
.then(json => console.log(json))
.catch(err => console.log)
它捕捉到一个错误
[TypeError: Network request failed]
当我删除代理并在 fetch 中手动输入地址时,它可以正常工作,并且我的服务器会收到 GET 请求。
fetch('http://localhost:3000')
.then(response => response.json())
.then(json => console.log(json))
.catch(err => console.log)
【问题讨论】:
标签: reactjs api react-native proxy fetch