.net webclient返回500错误,但浏览器中的URL可以 [英] .net webclient returns 500 error, but url in browser is fine

查看:75
本文介绍了.net webclient返回500错误,但浏览器中的URL可以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过Web客户端连接到url时,它返回500内部服务器错误.我可以在浏览器中访问该URL.这已经工作了几个月,问题从昨天开始.我没有任何改变.我了解到500状态代码是服务器错误,但是我想看看在吓坏我时是否还有其他事情可以做.

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.

示例网址: http://www.myfitnesspal.com/reports/printable_diary/chuckgross?from = 2015-07-17& to = 2015-07-17

代码:

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

这是一个例外:远程服务器返回错误:500.

This gives the exception: The remote server returned an error: 500.

使用Fiddler,我看到一个返回的页面,该页面是其站点向下"页面,并显示以下消息:对不起,但是在处理您的请求时发生服务器错误.我们的团队已收到有关此问题的通知."

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".

鉴于URL本身在浏览器中可以正常工作,我是否可以做些什么?还有其他尝试进行故障排除的方法吗?

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

推荐答案

似乎他们尝试通过查询 User-Agent 标头来检测服务器端的浏览器版本,但并不希望它丢失.

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

要解决客户端的错误,您可以例如使用IE 9使用的/a>发送请求之前:

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)";

这篇关于.net webclient返回500错误,但浏览器中的URL可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆