What's the difference between HttpResponseMessage and HttpWebResponse?

后端 未结 2 1089
借酒劲吻你
借酒劲吻你 2021-01-17 22:13

They both seem to be different ways of handling responses to the client.

More detail about my problem: I have a server in which when I receive a request from a clien

相关标签:
2条回答
  • 2021-01-17 22:50

    HttpResponseMessage represent a moden way to use Http. It is being used by REST solutions such as Web API to manipulate status code and the Location header.

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

    0 讨论(0)
  • 2021-01-17 23:08

    They both serve the same purpose.

    • HttpWebRequest/HttpWebResponse are available since the first version of .NET, and are still a perfectly valid approach.
    • HttpClient (which uses HttpRequestMessage and HttpResponseMessage to represent requests and responses) has been introduced in .NET 4.5, and offers a fully asynchronous API, along with a new model for request and response content; internally, it still relies on HttpWebRequest/HttpWebResponse.

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

    You can use the one you're most comfortable with; just be aware that since HttpClient is asynchronous, the code that uses it must be asynchronous as well.

    0 讨论(0)
提交回复
热议问题