小编Obv*_*ous的帖子

Web API POST方法返回HTTP/1.1 500内部服务器错误

正如标题所说,当使用Web API的post方法时,我有500个内部服务器错误.Get方法工作正常,只是在POST中出错.

我正在使用fidler发送帖子请求:

响应标头: HTTP/1.1 500内部服务器错误

请求标头: 用户代理:提琴手主机:localhost:45379内容类型:application/jsonContent-Length:41内容长度:41

请求 正文: {"iduser"="123456789","username"="orange"}

这是我的post方法代码:

     // 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);
        }
    }
Run Code Online (Sandbox Code Playgroud)

Sooooooo可能出错了什么?为什么它不允许我发帖?

rest web-services asp.net-mvc-4 asp.net-web-api

6
推荐指数
1
解决办法
6万
查看次数