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

最近在用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

转载于:https://www.cnblogs.com/rainbow57/p/3911880.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值