001
001

Reputation: 65205

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;charset=UTF-8
 Cache-Control: no-store
 Pragma: no-cache

 {
   "message":"response content example"
 }

Upvotes: 6

Views: 12756

Answers (3)

Y.L
Y.L

Reputation: 764

In AspNetCore:

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

Or using a dynamic object:

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

Upvotes: 1

SLaks
SLaks

Reputation: 887887

Use the Output and OutputStream properties, or the Write method.

Upvotes: 7

Michaël
Michaël

Reputation: 6734

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

Upvotes: 5

Related Questions