Skip to content

How to use both Proxy and Headers in AngleSharp.Io #29

@dlubart

Description

@dlubart

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() (or WithRequester() ) because they are separately part of AngleSharp and AngleSharp.Io but I cannot locate the proper syntax for doing both in the same request.

Apologies for the 'bug' label. Should be a help request but I can't figure out how to change that now.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions