web services - Web API POST method returns HTTP/1.1 500 Internal Server Error -


as title says have got 500 internal server error when using post method of web api. method working fine, getting error in post.

i using fidler send post request :

response header: http/1.1 500 internal server error

request header: user-agent: fiddler host: localhost:45379 content-type: application/jsoncontent-length: 41 content-length: 41

request body: {"iduser"="123456789","username"="orange"}

here code post method:

     // post api/user      public httpresponsemessage postuser(user user)      {         if (modelstate.isvalid)         {             db.users.add(user);             db.savechanges();              httpresponsemessage response =r  equest.createresponse(httpstatuscode.created, user);             response.headers.location = new uri(url.link("defaultapi", new { id = user.iduser }));             return response;        }        else         {             return request.createresponse(httpstatuscode.badrequest);         }     } 

sooooooo have possibly gone wrong? why not allowing me post?

the data in post not valid json-object, model binder expecting (content-type: application/json).

{"iduser"="123456789","username"="orange"} 

try replacing = : , see how on. code works on machine alterations in request.

post http://localhost:20377/api/test/postuser http/1.1 host: localhost:20377 connection: keep-alive content-length: 42 user-agent: mozilla/5.0 (windows nt 6.3; wow64) applewebkit/537.36 (khtml, gecko) chrome/30.0.1599.101 safari/537.36 origin: chrome-extension://fhjcajmcbmldlhcimfajhfbgofnpcjmb content-type: application/json accept: */* accept-encoding: gzip,deflate,sdch accept-language: en-gb,en;q=0.8,en-us;q=0.6,nb;q=0.4,de;q=0.2  {"iduser":"123456789","username":"orange"} 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -