I am developing a C # console application to validate a URL. It works well for most urls. But we found that in some cases, the application always received a 404 response from the target site, but the URLs do work in the browser. And these URLs also work when I tried them in tools like DHC (Dev HTTP Client).
At first, though this may be the reason for not adding the correct headers. But after trying to use Fiddler to compose an HTTP request with the same headers, it works in Fiddler.
So what about my code? Is there a bug in the .NET HttpClient?
Here is the simplified code for my test application:
class Program { static void Main(string[] args) { var urlTester = new UrlTester("http://www.hffa.it/short-master-programs/fashion-photography"); Console.WriteLine("Test is started"); Task.WhenAll(urlTester.RunTestAsync()); Console.WriteLine("Test is stoped"); Console.ReadKey(); } public class UrlTester { private HttpClient _httpClient; private string _url; public UrlTester(string url) { _httpClient = new HttpClient { Timeout = TimeSpan.FromMinutes(1) };
source share