码迷,mamicode.com
首页 > 编程语言 > 详细

C#调用Java的WebService出现500 服务器错误

时间:2014-08-14 10:43:38      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:des   blog   http   java   os   io   for   ar   

最近在用C#调用Java写的WebService时,发现老是返回500 服务器错误,到底什么原因一直找不出来,

后来google了以后,找到国外的http://stackoverflow.com站点已经有人碰到过这个问题了。

转帖如下:

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?

 

Answer:

try
{
    HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;

    WebResponse wr = req.GetResponse();
}
catch (WebException wex)
{
    var pageContent = new StreamReader(wex.Response.GetResponseStream())
                          .ReadToEnd();
}

 可以通过上面的代码查询具体的错误信息,再进一步解决问题。

原帖地址:

http://stackoverflow.com/questions/18403846/httpwebrequest-accept-500-internal-server-error

C#调用Java的WebService出现500 服务器错误,布布扣,bubuko.com

C#调用Java的WebService出现500 服务器错误

标签:des   blog   http   java   os   io   for   ar   

原文地址:http://www.cnblogs.com/rainbow57/p/3911880.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!