我还在学习网络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.