Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net webclient returns 500 error, but url in browser is fine

When I connect to a url via a web client, it returns a 500 internal server error. I can visit that URL in my browser just fine. This was working for months and the problem started yesterday. No changes on my end. I understand that a 500 status code is a server error, but I wanted to see if there was something else I could do at this point as I'm freaking out.

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 the exception: The remote server returned an error: 500.

Using Fiddler, I'm seeing a page returned that is their "Site Down" page with the message: "Sorry, but a server error occurred processing your request. Our team has been notified of the issue".

Is there anything that I can do given that the URL itself works fine in a browser? Any alternative ways to try to troubleshoot?

like image 716
CGross Avatar asked Jul 18 '15 13:07

CGross


1 Answers

It seems they try to detect browser version on server side by querying User-Agent header but do not expect it to be missing.

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

client.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)";
like image 73
dewaffled Avatar answered Oct 05 '22 23:10

dewaffled