gpt4 book ai didi

c# - RestSharp 的连接池

转载 作者:行者123 更新时间:2023-11-30 21:49:10 26 4
gpt4 key购买 nike

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

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

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

我正在使用 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 基于著名的 System.Net 类,例如 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.

相关问题:Is HTTP connection pooling possible?

关于c# - RestSharp 的连接池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37155179/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com