欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

.net Web API 2,return HttpResponseMessage with ObjectContent

程序员文章站 2022-03-16 10:25:14
...

public async TaskHttpResponseMessage Register(AllenRegistration model) { 1. Will return 400 Error return Request.CreateResponse( HttpStatusCode.BadReques t); 2. Will return Json Type like {return1:A,returnBL:B} return new HttpResponseMessa

public async Task Register(AllenRegistration model)

{

1.


Will return 400 Error

return Request.CreateResponse(HttpStatusCode.BadRequest);


2.

Will return Json Type like {"return1":"A","returnB"L:"B"}

return new HttpResponseMessage(HttpStatusCode.OK)

{
Content = new ObjectContent(new
{
return1="A",

return2="B"
}, Configuration.Formatters.JsonFormatter)
};
}

}