I have this piece of code below to send a request to an address that does a 302 redirect to another subdomain. This webpage requires 4 HTTP headers to be present and when using curl (both locally and on our server), I get the correct response, however, with .net 7/8 app the httpClient.SendAsync
method gets stuck and times out. The same code works locally, but does not work on our server.
How can I understand what is going on in this specific remote environment?
using var request = new HttpRequestMessage(new HttpMethod("GET"), "https://myhiddenaddres");
request.Headers.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36");
request.Headers.TryAddWithoutValidation("Accept", "application/json,text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
request.Headers.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate, br, zstd");
request.Headers.TryAddWithoutValidation("Accept-Language", "en-US,en;q=0.9");
var response = await httpClient.SendAsync(request);
This is the curl that works both locally and remote:
curl -k -i --raw "https://myhiddenaddres" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Geck
o) Chrome/125.0.0.0 Safari/537.36" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/we
bp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7" -H "Accept-Encoding: gzip, deflate, br, zstd" -H "Accept
-Language: en-US,en;q=0.9"