开发者

Set content body of httpresponse?

开发者 https://www.devze.com 2023-03-19 22:38 出处:网络
http://msdn.microsoft.com/en-us/library/system.web.httpresponse.aspx How do I set the content in the body?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消