Skip to content

Latest commit

 

History

History
19 lines (13 loc) · 1.19 KB

README.md

File metadata and controls

19 lines (13 loc) · 1.19 KB

UnityHttpClientFactory

Script file to properly use HttpClient in Unity applications

Background

This script was heavily influenced by this blog post: https://ticehurst.com/2021/08/27/unity-httpclient.html by Bill Ticehurst.

I've made significant changes and additions. I also verified that it works similarly to how the HttpClientFactory works, which is holding onto an HttpClientHandler, and recycling it every so often. Currently this code recycles it every 2 minutes, but it is up to the user of this script to determine how often the Handler should be recycled.

If DNS changes are not expected for the endpoints, a longer recycle time could be used.

This site section of the Microsoft documentation is applicable:

However, everything related to typed clients and IServiceCollection are not applicable to this script, as it is just the bare minimum to properly use HttpClient without all of the drawbacks listed in Bill's post.