angular - Ionic 3/Angular 4/5 http 帖子 - 未找到
问题描述
在邮递员中,我有:
POST: https://myapp.herokuapp.com/login
BODY: {"email": "myemail@gmail.com", "password": "123456"}
它有效。
在提供者中,我有:
public login(credentials): Observable<any> {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})};
return this.http.post(API_URL + '/login', {params: {email: credentials.email, password: credentials.password}}, httpOptions);
}
我得到Not Found
错误。在 Network 选项卡的控制台中,请求方法是 OPTIONS。怎么了?
编辑:我收到以下错误:
解决方案
尝试不使用params
:
public login(credentials): Observable<any> {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
return this.http.post(API_URL + '/login', {email: credentials.email, password: credentials.password}, httpOptions);
}
如果这不起作用,那么这可能是由于CORS
请求而发生的,这就是所谓的Preflighted request。OPTIONS
当您调用CORS
请求以了解实际允许的方法时,浏览器总是将请求发送到服务器。
看更多:
推荐阅读
- kubernetes - 如何使用 Gatekeeper 在没有 ResourceQuota 的情况下禁止命名空间中的 Pod?
- javascript - 在交换机外部、路由器内部调用时组件渲染两次。不使用严格模式
- c++ - 基本的 c++ 程序仅在一个内核上运行
- amazon-s3 - 在 Windows 上使用 RClone 挂载 s3 存储桶
- tfs - 为构建租约执行 Azure DevOps API 调用需要哪些权限
- api - 通过 API 密钥进行 $_SERVER 和标头身份验证
- python - 按需将列表保存为 JSON
- c# - XSD:如何重新定义基本模式的标签
- ios - NSKeyedUnarchiver 总是返回 nil
- pandas - 将 170 万条数据从雪花提取到 csv 文件时出错