How do you construct HtmlResponseMessage?

How do you construct HtmlResponseMessage?

1 Like

HttpResponseMessage works with HTTP protocol to return the data with status/error. It will predict the kind of response we can get - success or failure.

A HttpResponseMessage allows us to work with the HTTP protocol (for example, with the headers property) and unifies our return type. In simple words an HttpResponseMessage is a way of returning a message/data from your action.

public HttpResponseMessage Get()
{
HttpError myCustomError = new HttpError(“The file has no content or rows to process.”) { { “CustomErrorCode”, 42 } };
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, myCustomError);
}