I'm trying to get a CSV file with exchange rates from a URL on a bank's web site. When I manually access the link in a browser, I can download the exchange rates. Even on development machine (Win10, IIS 10) the code works fine to access the file. The problem arises when I move the app to the production server (Win2012 R2, IIS 8.5).
The WebException Response: <!DOCTYPE html> <html class="ltr" dir="ltr" lang="sk"><head> <title>Nepodporovaný prehliadač - ČSOB</title> <meta content="text/html; charset=UTF-8" http-equiv="content-type"> <link href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAF...
and it goes on like this - around 65 000 characters.
Nepodporovaný prehliadač = unsupported browser.
I tried setting the user agent as suggested here: .net webclient returns 500 error, but url in browser is fine:
WebClient client = new WebClient();
client.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)";
The exception still arises even with the user agent set this way.
I tried using WebRequest
instead of WebClient
(as suggested here: How to get content from file from this URL?) but the same exception happens with Error 500 and Response in WebException saying unsupported browser.
The URL I'm trying to access: https://www.csob.sk/delegate/getExchangeRatesExport?EXPORT_TYPE=CSV&DISPLAY=CURRENCY&DATE=2019011607
All the methods I've tried work fine in development but fail in production. The WebClient
code worked perfectly fine on production server for like a year until yesterday - probably the bank changed something. Any help would be much appreciated.