2012-09-22 30 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