Raí*_*ges 6 safari macos ios reactjs axios
我正在尝试使用 Axios 执行 API 请求,它适用于每个 Windows 和 Android 浏览器,但不适用于 MacOs Safari(但在 Chrome 中它工作正常)或任何 iOs 浏览器。
在相同的代码中,我再次调用相同的 API(不同的端点),它在 safari 和 iOs 中完全没有问题。
当我 console.log 抛出的异常结果是网络错误。
我不认为这是 CORS 问题,因为它适用于其他浏览器。
我的请求:
try {
const response = await api.get(
"/precos/get",
{
headers: {
'Content-Type': 'application/json'
'token': getToken()
}
}
);
this.filtraProdutoPorTabela(response.data.data);
} catch (err){
// do something with the error
}
Run Code Online (Sandbox Code Playgroud)
控制台错误:
网络错误 {"url":" http://url/precos/get ","method":"get","headers":{"Accept":"application/json, text/plain, / ","this .state-Type":"application/json","token":"e…c"},"baseURL":"the base url","transformRequest":[null],"transformResponse":[null]," timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"httpsAgent":{}}}
小智 0
我能想到的唯一会导致此问题的问题是,您肯定将计算机上的链接设置为例如:http://localhost:5000/api/posts
这工作正常,因为您在同一台机器上执行此操作,但是当您在移动设备或任何其他设备上尝试它时,当浏览器尝试访问该路由时,它会看到 url 的 localhost 部分,并且它指向它自己而不是您的实际路径机器。
要解决此问题,您必须输入计算机的 IP 地址和端口,而不是文字文本“localhost”。
来自:http://localhost:5000/api/posts
至: http: //192.168.1.23:500 /api/posts http://{您的 IP 地址}:5000/api/posts
| 归档时间: |
|
| 查看次数: |
1493 次 |
| 最近记录: |