I have a WebApi on which I have already sent a request from another application. Everything worked correctly. I wrote to WebApiConfig config.EnableCors(new EnableCorsAttribute("http://localhost:4200", headers: "*", methods: "*"));
Now I have created another application and I want to postpone my post-method on this API.
I created the form and wrote a method to submit it to the API
postUser(user: User) {
var httpOptions = { headers: new HttpHeaders({
'Content-Type': 'application/json'
})};
var body = JSON.stringify(user);
return this.http.post<User>('http://localhost:51251/api/Users', body, httpOptions);
}
I have created the same custom classes on ts and cs
export class User {
Id: number;
Email: string;
Password: string;
ConfirmPassword: string;
}
public class User
{
public int Id { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string ConfirmPassword { get; set; }
}
my post-method in API:
// POST: api/User
[ResponseType(typeof(User))]
public IHttpActionResult PostUser(User user)
{
db.Users.Add(user);
db.SaveChanges();
return CreatedAtRoute("DefaultApi", new { id = user.Id }, user);
}
In the console, log the body like this {"Id":null,"Email":"weferer@frr5","Password":"12","ConfirmPassword":"12"}
But no request goes anywhere, and I can not understand why. No mistakes are displayed. What could be the reason?