C#調用Java的WebService出現500 服務器錯誤

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

相關文章
相關標籤/搜索