문제

    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!

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top