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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM