开发者

WEbResponse throws 500 Internal server error

I have many times successfully implemented reading data from web pages using technique like this:

  WebRequest req = (WebRequest)WebRequest.Create(path);
  WebResponse resp = (WebR开发者_高级运维esponse)req.GetResponse(); etc.

.........

However, this time the WebResponse throws an internal error. Otherwise, I can browse the parameter path. What could be the reason?


I think it could be any number of reasons.

You should try to catch the error and see if you can get any further details from the response. Perhaps try adding the code below and see if that provides any further details:

catch (WebException webex)
{
Console.WriteLine("Unable to perform command: " + req);

String data = String.Empty;
if (webex.Response != null)
{
   StreamReader r = new StreamReader(webex.Response.GetResponseStream());
   data = r.ReadToEnd(); 
   r.Close();
}
Console.WriteLine(webex.Message);
Console.WriteLine(data);


Probably its not creating the request, WebRequest.Create, there can be a proxy issue if you are behind any proxy, i got the same problem that my code was unable to connect to any path but it was browsing fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜