设置httpresponse的内容主体?

时间:2011-07-11 13:21:34

标签: c# class httpresponse

http://msdn.microsoft.com/en-us/library/system.web.httpresponse.aspx

如何在正文中设置内容?

 HTTP/1.1 400 Bad Request  
 Content-Type: application/json;charset=UTF-8
 Cache-Control: no-store
 Pragma: no-cache

 {
   "message":"response content example"
 }

3 个答案:

答案 0 :(得分:2)

使用OutputOutputStream属性或Write方法。

答案 1 :(得分:1)

myHttpResponse.Write("\"{\"message\":\"response content example\"}\"");

答案 2 :(得分:0)

在AspNetCore中:

await context.Response.WriteJsonAsync("\"{\"message\":\"response content example\"}\"");

或使用动态对象:

await context.Response.WriteJsonAsync(new { message = "response content example" });