Different HttpClient headers

When I make an HTTP request in my browser (Chrome), I get different response headers than I do in my program using HttpClient with a HttpClientHandler I'm using all the exact same headers, including the same cookies, and making the request to the same URL - I also have redirects disabled Why could this be? Chrome shows me 11 headers, whereas C#'s HttpClient only shows me 6 headers from the exact same request
10 Replies
leowest
leowest9mo ago
unhappily its really hard to guess without code
Angius
Angius9mo ago
Are you spoofing the Chrome user agent as well?
leowest
leowest9mo ago
should if he is sending the same headers as he said
UnemployedNinja
UnemployedNinjaOP9mo ago
c#
HttpClientHandler handler = new HttpClientHandler();
handler.AllowAutoRedirect = false;
if (proxy != null) handler.Proxy = proxy;

using (HttpClient client = new HttpClient(handler, true))
using (HttpResponseMessage response = await client.GetAsync($"https://us.battle.net/")) {

client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br, zstd");
// ... More headers, including the cookies ...

if (response.StatusCode == HttpStatusCode.Found) {
HttpResponseHeaders headers = response.Headers;

var headersDict = headers.ToDictionary(a => a.Key, a => a.Value);

Console.WriteLine("\nHeaders:");
foreach (var (key, value) in headersDict) {
string valStr = "";
foreach (string val in value) { valStr += val; }
Console.WriteLine($" {key}: {valStr}");
}
}

}
c#
HttpClientHandler handler = new HttpClientHandler();
handler.AllowAutoRedirect = false;
if (proxy != null) handler.Proxy = proxy;

using (HttpClient client = new HttpClient(handler, true))
using (HttpResponseMessage response = await client.GetAsync($"https://us.battle.net/")) {

client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, br, zstd");
// ... More headers, including the cookies ...

if (response.StatusCode == HttpStatusCode.Found) {
HttpResponseHeaders headers = response.Headers;

var headersDict = headers.ToDictionary(a => a.Key, a => a.Value);

Console.WriteLine("\nHeaders:");
foreach (var (key, value) in headersDict) {
string valStr = "";
foreach (string val in value) { valStr += val; }
Console.WriteLine($" {key}: {valStr}");
}
}

}
Yes
leowest
leowest9mo ago
you're adding the headers after u made the request it needs to be done before
UnemployedNinja
UnemployedNinjaOP9mo ago
omfg ok.......................
leowest
leowest9mo ago
you add your headers to the HttpClientHandler
UnemployedNinja
UnemployedNinjaOP9mo ago
ty lol I'm so dumb
leowest
leowest9mo ago
and that's why posting code = quick job
UnemployedNinja
UnemployedNinjaOP9mo ago
An hour of my life................... ty lol
Want results from more Discord servers?
Add your server