What is the difference between HttpResponseMessage and HttpWebResponse?

Both of them seem to be different ways of handling responses to the client.

More about my problem: I have a server on which, when I receive a request from a client, I want to call the second server and return a response from this second server to my client.

+8
source share
2 answers

Both of them fulfill the same goal.

  • HttpWebRequest / HttpWebResponse available since the first version of .NET and is still an absolutely correct approach.
  • HttpClient (which uses HttpRequestMessage and HttpResponseMessage to represent requests and responses) was introduced in .NET 4.5 and offers a completely asynchronous API, as well as a new model for request and response content; internally, it still relies on HttpWebRequest / HttpWebResponse .

An important difference is that HttpWebRequest/Response presents a request and response only from the client's point of view, while HttpRequestMessage/HttpResponseMessage can be used either by the client or by the server (ASP.NET Web API uses these types to communicate with the client).

You can use the one you like best; just keep in mind that since HttpClient is asynchronous, the code that uses it must also be asynchronous.

+9
source

HttpResponseMessage are the moden way of using Http. It is used by REST solutions, such as the Web API, to manage the status code and location header.

HttpWebResponse is an old goold class that contains all the Http information but considers obsolete.

+1
source

All Articles