重复使用httpclient f#如何重复使用
大家好,我是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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不专门了解甘草。在常规的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
withvar 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