How do I check for binary vs. text in an HttpWebRequest in c#? -


is there way determine if response httpwebrequest in c# contains binary data vs. text? or there class or function should using this?

here's sample code. i'd know before reading streamreader if content not text.

httpwebrequest request = (httpwebrequest)webrequest.create("http://www.someurl.com"); request.method = webrequestmethods.http.get; using (webresponse response = request.getresponse()) {     // check somewhere in here if response binary data , ignore      using (streamreader reader = new streamreader(response.getresponsestream()))     {         string responsedetails = reader.readtoend().trim();     } } 

in general, web sites tell in content-type header kind of data they're returning. can determine getting contenttype property response.

but sites have been known lie. or not anything. i've seen both. if there no content-type header or don't want trust it, way can tell kind of data there, reading it.

but then, if don't trust site, why reading data it?


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -