最近在用C#调用Java写的WebService时,发现总是返回500 服务器错误,到底什么缘由一直找不出来,web
后来google了之后,找到国外的http://stackoverflow.com站点已经有人碰到过这个问题了。服务器
转帖以下:this
HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest; WebResponse wr = req.GetResponse();
When the server returns 500 Internal Server Error, exception is thrown in req.GetResponse(). I would like the GetResponse() to accept this Response Code, it is normal for the passed url to throw this Response Code. I would like to parse the Html despite Response Code 500 Internal Server Error. Is it possible to say to GetResponse() method not to verify the Response Code?google
Answer:url
try { HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest; WebResponse wr = req.GetResponse(); } catch (WebException wex) { var pageContent = new StreamReader(wex.Response.GetResponseStream()) .ReadToEnd(); }
能够经过上面的代码查询具体的错误信息,再进一步解决问题。orm
原帖地址:server
http://stackoverflow.com/questions/18403846/httpwebrequest-accept-500-internal-server-errorblog