api - 托管在 localhost 上的 ionic 请求 api 中的 CORS 问题
问题描述
我的 Ionic 应用程序正在运行http://localhost:8100/
,我正在请求http://localhost:40410/api/myApi
api。
我知道它会出现 CORS 问题,我尝试通过添加代理ionic.config.json
设置
"proxies": [
{
"path": "/api",
"proxyUrl": "http://localhost:40410/"
}
]
当我ionic serve
在控制台上得到这个输出时Proxy added:/api => https://localhost:44381/
,但在应用程序中,我无法从 api 获取任何数据。
这就是我在 chrome 开发工具中得到的
Request URL: http://localhost:8100/api/myApi
Request Method: GET
Status Code: 500 Internal Server Error
Remote Address: 127.0.0.1:8100
这是我的 ts 代码,
this.http.get('/api/myApi').subscribe(
(data) => {
console.log(data.json());
},(error) =>{
console.log(error);
}
);
解决方案
您可以使用以下参数运行 chrome 以禁用 cors 保护。--禁用网络安全
推荐阅读
- python - 在 MetPy 中计算多个垂直水平的涡度
- pharo - 必须声明临时变量而不是绑定的原因是什么?
- html - 当“顶部”值更改时,文本不会留在父 div 中
- c++ - Qt5对QInputDialog和QMessageBox的未识别引用..错误
- python - 使用 Python 获取 SVN 存储库的根目录
- ansible - 如何遍历列表的字典并将变量传递给 Ansible 角色?
- windows - 在 Buildbot 中设置和获取属性
- xamarin - Xamarin 表单 - 动态更改网格行可见性
- javascript - VueJS 首先导航到根路由
- google-chrome - Chrome 扩展:无法监听通过服务工作者进行的网络调用