Badrequest ответ от сервера, когда он - PullRequest
0 голосов
/ 18 ноября 2018

Мне нужно создать страницу регистрации.

когда мне нужно отправить данные с angular6 на сервер, как мне это ошибка:

: 44390 / api / role / CreateRole: 1 POST https://localhost:44390/api/role/CreateRole 400 (Плохой запрос) role-service.service.ts: 96 HttpErrorResponse {заголовки: HttpHeaders, status: 400, statusText: «Плохой запрос», URL: «https://localhost:44390/api/role/CreateRole", ok: false,…} (анонимно) @ role-service.service.ts: 96 push ../ node_modules / rxjs / _esm5 / internal / operator / catchError.js.CatchSubscriber.error @ catchError.js: 33 role-service.service.ts: 102 добавление не выполнено: реакция на ошибку Http дляhttps://localhost:44390/api/role/CreateRole: 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'))
    );
  }
...