RestSharp 的连接池

Pool of connections for RestSharp

有什么方法可以建立自己的连接池吗

我正在开发一个连接到服务器的应用程序。每次它需要向服务器请求一些东西时,它都会创建一个连接并释放它。

我想提供一种透明的方式来从它们的池中获取连接。

我正在使用 RestSharp 构建我的请求:

var client = new RestClient("http://example.com");

var request = new RestRequest("resource/{id}", Method.POST);
request.AddParameter("name", "value");
request.AddUrlSegment("id", "123");

// easily add HTTP Headers
request.AddHeader("header", "value");

// execute the request
IRestResponse response = client.Execute(request);
var content = response.Content;

那么,问题可能是如何为 RestSharp 创建池?或者,如何配置 RestSharp 从池中获取连接?

正如您在 RestSharp source code, RestSharp is based on well-known System.Net classes, such as HttpWebRequestHttpWebResponse 中看到的那样。这些 类 已经在使用自己的管道。

如果需要,可以调整此管道: Understanding System.Net Connection Management and ServicepointManager

If application continues to make requests, all pending requests would be queued on the ServicePoint and processed sequentially. If pipeline is turned on, then request is send on the connection and put in the queue of the connection. If pipelining is turned off then request would remain on the queue of the servicepoint and would be sending on the connection, as soon as free connection is available.

相关问题: