相关疑难解决方法(0)

web-api POST正文对象始终为null

我还在学习网络API,所以请原谅我,如果我的问题听起来很愚蠢.

我有这个StudentController:

public HttpResponseMessage PostStudent([FromBody]Models.Student student)
        {
            if (DBManager.createStudent(student) != null)
                return Request.CreateResponse(HttpStatusCode.Created, student);
            else
                return Request.CreateResponse(HttpStatusCode.BadRequest, student);
        }
Run Code Online (Sandbox Code Playgroud)

为了测试这是否有效,我使用Google Chrome的扩展程序"Postman"来构建HTTP POST请求以对其进行测试.

这是我的原始POST请求:

POST /api/Student HTTP/1.1
Host: localhost:1118
Content-Type: application/json
Cache-Control: no-cache

{"student": [{"name":"John Doe", "age":18, "country":"United States of America"}]}
Run Code Online (Sandbox Code Playgroud)

"student"应该是一个对象,但是当我调试应用程序时,API接收学生对象,但内容始终是NULL.

c# rest asp.net-web-api

62
推荐指数
9
解决办法
16万
查看次数

标签 统计

asp.net-web-api ×1

c# ×1

rest ×1