2012-09-22 42 views
1

我偶然發現了WebClient的一個瘋狂行爲,它在404代碼上拋出WebException。WebClient在404上拋出異常

此行爲是錯誤的,因爲404代碼可以與內容數據的Facebook的情況下返回,如:https://graph.facebook.com/sadfsa.dsadsasadsa

所以這個代碼拋出一個異常

var json = webClient.DownloadString("https://graph.facebook.com/sadfsa.dsadsasadsa"); 

我讀了JSON返回如何通過404 Facebook?

+1

http://stackoverflow.com/questions/8915785/webclient-downloadstringurl-when-this-url-returns-a-404-page- how-can-i-skip-t – dumdum

回答

3

我不認爲有WebClient的瘋狂行爲。試圖抓住WebException和閱讀webException.Response.GetResponseStream

看到一個類似的問題:C# WebException how to get whole response with a body?

+4

如果你不認爲WebClient具有瘋狂行爲,那太糟糕了 – user1615362

+2

除了200以外的http狀態碼不是一個例外狀態。 – fusi