Web API Return 400 BAd Request

12 views
Skip to first unread message

arjunender pabba

unread,
Oct 25, 2019, 11:50:38 AM10/25/19
to Angular and AngularJS discussion
Hi


c# Web API Returning 400: BAD REQUEST - The request could not be processed by the server due to invalid syntax

from angular httpclient post method but

the same is working with get method

in Postman every thing is working fine

Here is the angular code

var headers = new HttpHeaders();
    headers.append('Content-Type', 'application/json');
var options = {
      headers: headers
   }
this.http.post(this.url,
   {
    "User_Id":  "1",
    "User_Name":  "arjun",    
},options)
.subscribe(
data  => {
console.log("POST Request is successful ", data);


Web API Code :

public HttpResponseMessage Post([FromBody]User user) {
  var message = Request.CreateResponse(HttpStatusCode.Created, user);

                    return message;
}


Any suggessions

Thanks
Arjun
Reply all
Reply to author
Forward
0 new messages