Search code examples
httpwebrequestwebclient

WebClient request fails because client is seen as outdated browser


I'm attempting to download an HTML response from a website but I keep getting the following response: The security settings for your Internet browser or device appear to be out of date. Please upgrade now.

I've attempted to use every User-Agent setting I could find but I'm still receiving the same error. I've also tried the HTTPWebRequest method and received the same error.

The request works fine when I open IE or Chrome and type URL.

Here is my code:

    string url = @"https://www.royalmail.com/track-your-item?trackNumber=" + track.TrackingNumber;
        WebClient client = new WebClient();
        client.Headers.Add("user-agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)");
        string content = client.DownloadString(url);

Example of URL that I'm trying to call: https://www.royalmail.com/track-your-item?trackNumber=FP065628015GB


Solution

  • You should use TLS1.2 as your security protocol for this site. This line should fix your problem.

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;