1

I have stumbled across an insane behavior of WebClient where it throws WebException on 404 code.

This behavior is wrong because the 404 code can be returned with content data like in the case of Facebook: https://graph.facebook.com/sadfsa.dsadsasadsa

So this code throws an exception

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

How do I read the json returned by 404 Facebook?

user1615362
  • 3,657
  • 9
  • 29
  • 46
  • 1
    http://stackoverflow.com/questions/8915785/webclient-downloadstringurl-when-this-url-returns-a-404-page-how-can-i-skip-t – dumdum Sep 22 '12 at 23:18

1 Answers1

3

I don't think that WebClient has insane behavior. Try to catch WebException and read webException.Response.GetResponseStream

See a similar question: C# WebException how to get whole response with a body?

Community
  • 1
  • 1
L.B
  • 114,136
  • 19
  • 178
  • 224