尝试将内容加载到 xdocument 时出现内部服务器错误
XDocument xDoc = new XDocument();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.Timeout = 1000 * 60 * 5;
WebResponse res = req.GetResponse();
Stream responseStream = res.GetResponseStream();
xDoc = XDocument.Load(responseStream);
responseStream.Close();
我正在尝试使用上面的代码将 uri 加载到 xdocument 中。我正在使用 HttpWebRequest 和 WebResponse 来避免超时错误。
现在的问题是,大多数时候代码确实可以工作,但在我之前遇到“超时”错误时,现在在尝试使用上述代码时遇到“内部服务器错误(500)”。关于如何解决这个问题有任何线索吗?代码示例会有很大帮助。
谢谢!
XDocument xDoc = new XDocument();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.Timeout = 1000 * 60 * 5;
WebResponse res = req.GetResponse();
Stream responseStream = res.GetResponseStream();
xDoc = XDocument.Load(responseStream);
responseStream.Close();
I am trying to use the above code to load a uri into an xdocument. I am using the HttpWebRequest and WebResponse to avoid the timeout error.
Now the problem is that most of the times the code does work but at the point where I was getting a "timeout" error before, now I am facing an "Internal server error (500)" when trying to use the above code. Any clues as to how to solve this issue? Code examples would be of great help.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能弄错了,但是 Http 500 Interal 服务器错误是由托管您调用的 uri 的服务器生成的。您的代码可能是正确的,但服务器返回错误。您需要调试服务器脚本(如果您控制它)或者处理代码中的 http 500 错误。
您应该直接从浏览器调用 uri,看看是否会触发 http 500 内部服务器错误。如果是这样(并且您控制网络服务器),您可以检查服务器日志以获取更多详细信息。
希望这有帮助。
I might be mistaken, but the Http 500 Interal server error is being generated by the server hosting the uri that you call. Your code might be correct, but the server is returning an error. You need to debug the server script (if you control it) or alternatively handle the http 500 error in your code.
You should call the uri directly from a browser to see if that triggers the http 500 internal server error. If so (and you control the web server) you could check the server log for more details.
Hope this helps.