我在获取本地部署的 API (Firebase) 时遇到错误。在 Web 浏览器中粘贴 API 链接有效,但在我的本机反应应用程序中无效。调用该函数时,它返回一个网络请求失败错误,当我检查调试时,没有具体的错误。这是获取功能:
const SignInPress = async () => {
try {
const response = await fetch(
'http://127.0.0.1/:5001/freelance-services-api-a0277/us-central1/app/api/freelancers',
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
'ACCESS-CONTROL-ALLOW-ORIGIN': '*',
},
},
);
const json = await response.json();
return json;
} catch (error) {
console.error(error);
}};
我尝试了不同的方法,例如更改IP地址和修改Android.xml文件使其接受http链接,但错误仍然存在。