重复使用httpclient f#如何重复使用

发布于 2025-02-05 16:39:43 字数 325 浏览 3 评论 0原文

大家好,我是F#中的新手

,我用长颈鹿创建了一个起动项目,然后我想对另一个API进行帖子

,并遇到重复使用HTTPCLCLIENT并更有效地使用套接字的问题。

let url = "https://someUrl"
let httpClient = new HttpClient ()
let! content = postAsync httpClient url Data
        
let result= JsonConvert.SerializeObject(result)

提出Web请求并重复使用HTTPClient有多正确?

hello everyone i'm new in f#

i created a starter project with giraffe and then i want to make post calls to another api

and ran into the problem of reusing HttpClient and using sockets more efficiently.

let url = "https://someUrl"
let httpClient = new HttpClient ()
let! content = postAsync httpClient url Data
        
let result= JsonConvert.SerializeObject(result)

How correct is it to make web requests and reuse HttpClient?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[浮城] 2025-02-12 16:39:43

我不专门了解甘草。在常规的ASP.NET核心应用中,您在启动期间添加httpclientFactory
service.addhttpclient()似乎应该称为AddHttpClientFactory ),

然后将ihttpclientFactory的实例注入controller作为构造服务器参数。

在控制器内部创建httpclient
var client = _httpclientfactory.createclient()

然后配置客户端设置并根据需要使用客户端提出请求。

工厂将管理幕后实例的汇总。

也许有一些变化可以适应甘草。

另请参见
使用ihttpplcclientfactory in asp in asp in asp insp insp insp insp insp insp insp insp insp insp insp insp insp insp insp insp insp in。净核心

I don't know about Girafe specifically. In a regular ASP.NET core app you add the HttpClientFactory during the startup with.
service.AddHttpClient() (Seems like this should be called AddHttpClientFactory)

Then inject an instance of IHttpClientFactory into a controller as a constructor parameter.

Inside the controller create an HttpClient with
var client = _httpClientFactory.CreateClient()

Then configure the client settings and make requests using the client as needed.

The factory will manage the pooling of instances behind the scenes.

Maybe some variation on that can be adapted to Girafe.

See also
Make HTTP requests using IHttpClientFactory in ASP.NET Core

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文