question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to customize HttpClientRequester with Default Headers?

See original GitHub issue

How do I add a Header to a configuration using Proxy? Every time I try to add Header, the proxy stops working.

With this code the proxy works:

_handler = new HttpClientHandler() { Proxy = new WebProxy("127.0.0.1", 8888), UseProxy = true, }; _config = Configuration.Default.WithRequesters(_handler).WithJs().WithDefaultLoader().WithDefaultCookies();

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
FlorianRapplcommented, Oct 14, 2019

If you really want to change the agent for HttpClientRequester I would explicitly use it (with a HttpClient instance).

var handler = new HttpClientHandler
{
  Proxy = new WebProxy("127.0.0.1", 8888),   
  UseProxy = true,
  UseCookies = false,
  AllowAutoRedirect = false,
};
var client = new HttpClient(handler);
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0");
var requester = new HttpClientRequester(client);
var config = Configuration.Default
  .With(requester)
  .WithJs()
  .WithDefaultLoader()
  .WithTemporaryCookies();

Hint: if you load AngleSharp.Io anyway, then also use the much better / advanced cookie container from it.

Hope that helps!

0reactions
gsscodercommented, Nov 29, 2019

@FlorianRappl, again thank you for your time and fast & depth reply.

Using reliply.org is very cool thing, thank you for showing it! Doing something would have been my next move. Impossible solve problems without certainties.

So now it’s clear, the server (in my case google.com) is simply ignoring the Accept-Language headers. I’m posting same query string by hand with a Chrome setted to en-US and results are different. When I use AngleSharp I don’t know why but Google understand that the request is made from Italy (where I live).

Thanks very much for your help, it was very useful. Beyond that it’s no longer due to AngleSharp (which I’m starting really to love)…

Have a nice day!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set the Content-Type header for an HttpClient ...
using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("http://example.com/"); httpClient.DefaultRequestHeaders.Add(" ...
Read more >
C# - How to add or remove headers using the HttpClient
You can set default headers on the HttpClient using the DefaultRequestHeaders property: _httpClient.DefaultRequestHeaders.Add( ...
Read more >
HttpClient.DefaultRequestHeaders Property
The DefaultRequestHeaders property represents the headers that an app developer can set, not all of the headers that may eventually be sent with...
Read more >
Custom HTTP Header with the Apache HttpClient
In this tutorial, we'll look at how to set a custom header with the HttpClient. If you want to dig deeper and learn...
Read more >
Add a Custom HTTP Header with the HttpClient
Instead of setting the same headers on every request, we can set default headers that will be added to each request automatically. import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found