AngleSharp.Io Proxy Settings with HttpClientRequester
Attach one proxy-aware HttpClientRequester before enabling the default loader.
AngleSharp’s loader delegates downloads to registered requesters. With AngleSharp.Io, attach a proxy-aware HttpClientRequester explicitly:
using AngleSharp;
using AngleSharp.Io.Network;
var handler = new System.Net.Http.HttpClientHandler
{
UseProxy = true,
Proxy = new System.Net.WebProxy(
"http://proxy.example.net:8080")
};
var http = new System.Net.Http.HttpClient(handler);
http.DefaultRequestHeaders.UserAgent.ParseAdd("ExampleReader/1.0");
var configuration = Configuration.Default
.With(new HttpClientRequester(http))
.WithDefaultLoader();
var context = BrowsingContext.New(configuration);
Use this context for the intended OpenAsync navigation. An endpoint from the HTTP proxy list can supply the WebProxy address for public web downloads. Keep the underlying HTTP client alive for that workload and dispose owned resources afterward.
WithRequesters is an alternative that registers the requesters available from AngleSharp.Io. Do not combine it with several manually configured HTTP requesters unless their selection is intentional. A proxy configured on one requester does not configure another implementation selected for a request.
Custom default headers on http belong to the destination request. Header values describing a request body, including Content-Type, should match that request rather than being forced globally onto every download.
Register the requester before WithDefaultLoader so the loader can use the intended HTTP service instead of adding its default when none exists.