I am trying to get AngleSharp to use both a proxy and set header properties like this:
var handler = new HttpClientHandler
{
Proxy = new WebProxy(ProxyMan.GetProxy()),
UseProxy = true,
PreAuthenticate = true,
UseDefaultCredentials = false
};
var requester = new DefaultHttpRequester();
requester.Headers["User-Agent"] = Tools.GetAgentString();
requester.Headers["Accept-Language"] = "en-US";
requester.Headers["Accept-Charset"] = "ISO-8859-1";
requester.Headers["Content-Type"] = "text/html; charset=UTF-8";
var config = Configuration.Default
.WithRequesters(handler)
.With(requester)
.WithTemporaryCookies()
.WithDefaultLoader();
var context = BrowsingContext.New(config);
var doc = await context.OpenAsync(Url);
When I added the Header requester, it stopped the proxy handler from working. I know there is some conflict between the .WithRequesters() and the .With() but I cannot locate the proper syntax for doing both in the same request.
Thanks.
Yeah I am not sure why you use both.
DefaultHttpRequester
is the requester from AngleSharp and usesWebClient
underneathWithRequesters
comes from AngleSharp.Io and adds all available requesters (incl.HttpClientRequester
)WithDefaultLoader
puts a loader into the config and registers the default HTTP requester, if no other requester has been registered yetI think what you want to do should be actually done using the
HttpClientRequester
directly.