angular - 使用 URL 中的参数发送 Post 请求
问题描述
任何注册后,我都会推动用户验证他的帐户。我将验证码发送到他的电子邮件,他将其添加到输入中并通过发布 API 调用发送该值。我的问题是,当我提出请求时,我得到了 203 Non-Authoritative Information 的响应。但是当我用 PostMan 尝试这个过程时,它工作正常
我的组件代码:
verfiy(){
this.code = this.userverfiycode.verfiCode;
this.authService.postData('Verify?userId='+this.user +'&vCode='+ this.code ).then((result) => {
this.responseData = result;
console.log(this.responseData);
console.log(this.user);
console.log(this.code);
console.log(this.type);
if (this.responseData = true) {
this.pushpage()
}
else{
console.log("");
}
}, (err) => {
// Error log
});
}
我的提供者代码:
let apiUrl = 'http://localhost:50494/api/Account/';
let apiKey = 'sdf4rw-23fs-3454-fsdsd-3we2693243424';
@Injectable()
export class AuthProvider {
constructor(public http : Http) {
console.log('Hello AuthService Provider');
}
UserKey = localStorage.getItem('loginData');
postData( type) {
return new Promise((resolve, reject) => {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('token', apiKey);
headers.append('api_key', this.UserKey);
this.http.post(apiUrl + type, {headers: headers})
.subscribe(res => {
resolve();
console.log()
}, (err) => {
reject(err);
console.log()
});
});
}
解决方案
一般post()的第二个参数是data,第三个是{headers};
你能尝试发送一些虚拟数据吗
this.http.post(apiUrl + type, {}, {headers: headers})
.subscribe(res => {});
我这么认为是因为后端没有获取您在 post() 函数中发送的标头。
您能否检查您的 devtool 网络选项卡是否有此请求,如果Request Headers
运行正常
推荐阅读
- javascript - 单击时隐藏具有相同名称的其他类的类
- spring - spring-session 会话实现没有获得 CGLIB 增强代理 Bean
- postgresql - 用于存储货币价值的数字与实数数据类型
- javascript - jQuery 子选择器找不到 DOM 对象
- airflow - 使用气流的多个 DAG 的最佳设置是什么?
- python - 在 pyinstaller .exe 打包中包含文件夹
- excel - 当数据变化时,使用 VBA 验证新的月度数据的公式,本月不起作用
- c# - 从 LINQ To SQL 类填充的 WPF 组合框显示类型而不是名称
- java - 如何将 GeoTools 导入 Intellij IDEA 中的现有项目?
- mysql - 使用游标循环存储过程并将返回值存储到变量中