.net webclient returns 500 errors but browser url is fine

When I connect to the URL through the web client, it returns an internal backend error. I can just visit this URL in my browser. This worked for months and the problem started yesterday. No changes at my end. I understand that status code 500 is a server error, but I wanted to see if there is anything else that I could do at this point, as I am worried.

Example url: http://www.myfitnesspal.com/reports/printable_diary/chuckgross?from=2015-07-17&to=2015-07-17

The code:

 string results;
 using (var client = new WebClient())
 {
    results = client.DownloadString(url);
 }

This gives an exception: an error occurred on the remote server: 500.

Using Fiddler, I see a return page, which is their β€œSite Down” page with the message: β€œSorry, but a server error occurred while processing your request. Our team was notified of the problem.”

Is there anything I can do, given that the url itself works fine in the browser? Any alternative troubleshooting methods?

+4
source share
2 answers

They seem to be trying to determine the version of the browser on the server side by requesting a header User-Agent, but don't expect it to be absent.

To fix the error on the client side, you can, for example, fill it with one used IE 9 before sending the request:

client.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)";
+8
source

, HTTP WebClient, , . , html-. , stream .

0

Source: https://habr.com/ru/post/1598510/


All Articles