Set content body of httpresponse?
http://msdn.microsoft.com/en-us/library/system.web.httpresponse.aspx
How do I set the content in the body?
HTTP/1.1 400 Bad Request
Content-Type: application/json;cha开发者_开发知识库rset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"message":"response content example"
}
Use the Output
and OutputStream
properties, or the Write
method.
myHttpResponse.Write("\"{\"message\":\"response content example\"}\"");
In AspNetCore:
await context.Response.WriteJsonAsync("\"{\"message\":\"response content example\"}\"");
Or using a dynamic object:
await context.Response.WriteJsonAsync(new { message = "response content example" });
精彩评论