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);
}
6
  • what are the headers on the request? What is your content-Type? Commented Jun 2, 2018 at 17:21
  • you mean this? i.imgur.com/CDsPXnC.png Commented Jun 2, 2018 at 18:46
  • From that picture it shows you getting a 500 error, is that because user is null? Commented Jun 2, 2018 at 19:32
  • Yes, because its null Commented Jun 2, 2018 at 19:56
  • try this: stackoverflow.com/questions/48852189/… Commented Jun 3, 2018 at 6:20

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.