0

I have a problem with my API.

So when I'm in my IDE and run my code through ng serve and dotnet run everything works fine and I get values in my backend. But when I publish my code and try it on my server the FromBody var is null.

Also in the Chrome Dev Tools, I see the values in the Request Payload.

Why the Oberservable? Because that is my result and I do not know the other way.

Broken API

Working in IDE but not when published

My TypeScript

signupUser(user: User): Observable<boolean> {
  return this.http.post<boolean>('api/user/signupuser', user);
}

My C#

[HttpPost]
public bool SignUpUser([FromBody]User user)
{
    return UserBusinessLayer.SignUpUser(user);
}

Working API

Working in IDE and when published

TypeScript

loginUser(email: string, password: string): Observable<boolean> {
  return this.http.post<boolean>('api/user/loginuser', {email: email, password: password});
}

C#

[HttpPost]
public bool LoginUser([FromBody]User user)
{
    return UserBusinessLayer.LoginUser(user);
}
Iman Bahrampour
  • 6,180
  • 2
  • 41
  • 64
Henrik
  • 1
  • 2

1 Answers1

0

Through testing I found an exception.

Turns out the User object was always null because it couldn't be casted.

I had a telephone number in the object stored as int. But the number had too many numbers.

So I used a string instead and everything works fine now.

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Henrik
  • 1
  • 2