presponseMessage和HttpWebResponse

presponseMessage和HttpWebResponse

本文介绍了什么是之间的Htt presponseMessage和HttpWebResponse区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他们都似乎是处理响应到客户端不同的方式。

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 client I want to call a second server and return the response from that second server to my client.

推荐答案

他们都达到同样的目的。

They both serve the same purpose.

  • 的HttpWebRequest / HttpWebResponse 可用,因为.NET的第一个版本,并且仍然是一个非常有效的方法。
  • 的HttpClient (使用的Htt prequestMessage 的Htt presponseMessage 来重新present请求和响应)已被引入在.NET 4.5,并提供了一​​个完全异步的API,以及用于请求和响应内容的新的模型;在内部,它仍然依赖于的HttpWebRequest / HttpWebResponse
  • 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.

这是很重要的区别是,的HttpWebRequest /响应重present从一个客户点的请求和响应只,而的Htt prequestMessage / Htt的presponseMessage 可以是客户机或服务器使用(的ASP.NET Web API使用这些类型与客户端进行通信)。

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).

您可以使用一个你最舒服的;要知道,因为的HttpClient 是异步的,使用它必须是异步的,以及在code。

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.

这篇关于什么是之间的Htt presponseMessage和HttpWebResponse区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:41