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);
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.