我需要创建一个注册页面。
当我需要将数据从angular6发送到服务器时,如何处理此错误:
:44390 / api / role / CreateRole:1 POST https://localhost:44390/api/role/CreateRole 400(错误请求) role-service.service.ts:96 HttpErrorResponse {headers:HttpHeaders,status:400,statusText:“ Bad Request”,url:“ https://localhost:44390/api/role/CreateRole”,ok:false,...} (匿名)@ role-service.service.ts:96 push ../ node_modules / rxjs / _esm5 / internal / operators / catchError.js.CatchSubscriber.error @ catchError.js:33 role-service.service.ts:102 addrole失败:https://localhost:44390/api/role/CreateRole的Http失败响应:400错误的请求
此地址当前为。 https://localhost:44390/api/role/CreateRole
出什么问题了?我怎么解决这个问题 ?
这是我的代码:
Register.ts
AddUser(){
console.log(this.register);
this.userService.RegisterUser(this.register).subscribe((data)=>{
console.log(data)
});
}
服务:
baseUrl="https://localhost:44390/api/register/";
user:IUser;
private headers:HttpHeaders;
constructor(private http:HttpClient) {
this.headers=new HttpHeaders({'Content-Type': 'application/json; charset=utf-8'});
}
/*
********************************
******** Register User *********
********************************
*/
public RegisterUser(user:IRegister):Observable<IRegister>{
console.log(this.baseUrl+'RegisterUser',user,{headers:this.headers});
return this.http.post<IRegister>(this.baseUrl+'RegisterUser',user,{headers:this.headers}).pipe(
tap((register: IRegister) => this.log(`register user w/ email=${register.email}`)),
catchError(this.handleError<IRegister>('register user'))
);
}