angular - http://localhost:4200' 已被 CORS 策略阻止:对预检请求的响应未通过
问题描述
我有一个我似乎无法弄清楚的问题。我想使用以下代码从我的 Angular 客户端向服务器发送一个 http 参数请求,但我遇到了异常:
http://localhost:4200' 已被 CORS 策略阻止:对预检请求的响应未通过
我想澄清一下,我是否在 Angular 中犯了任何错误,或者这是服务器端问题?
授权:
login(username: string, password: string) {
let params = new HttpParams();
params = params.append('email', username);
params = params.append('password', password);
return this.http.post<any>('URL',{params:params})
.pipe(map(user => {
if (user && user.token) {
}
}),
catchError(this.handleError)
);
}
解决方案
在运行应用程序之前在 VSCode 中添加配置(F5)
"runtimeArgs": ["--disable-web-security"]
在 launch.json 文件中
推荐阅读
- azure-sql-database - ADFV2、VNET 和链接服务
- python - 在 Keras 中对 4D 数据执行 Conv2D
- android - 搜索过滤器不在列表视图中显示搜索到的项目
- leaflet - 单击标记后,地图如何以移动标记为中心?
- php - 如何在论坛中增加以下视图
- javascript - 使用 Chrome 扩展(特别是)修改 Twitch 剪辑 DOM
- c++ - 一段时间后 SolvePNP 返回错误的 rvec 和 tvec
- azure - Azure 存储帐户与存储作为 RG 中的资源
- django-models - Django:如何在两个数据库表中搜索,或者两个如何合并两个相关的类
- go - 检查符文是否在基本多语言平面中的正确方法是什么?