Home  >  Article  >  Database  >  .net Web API 2,return HttpResponseMessage with ObjectContent

.net Web API 2,return HttpResponseMessage with ObjectContent

WBOY
WBOYOriginal
2016-06-07 15:44:281460browse

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)
            };
        }


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn