views:

121

answers:

2

Hi,

QUESTION: Anyone have some code they could post that will download a file from a URL/Link that will automatically handle: (a) binary or text based (b) gzip encoded

BACKGROUND: I've been starting to do this but hitting hurdles. Like I was using WebClient however it seems it can't handle the gzip bit (need to drop back to HTTPWebRequest). Also I'm getting a little confused re how to tell if the link/URL (e.g. taken from a HTML page) is really Text or Binary. Is there a well list of all content types that would be TEXT, or the ones that would be BINARY?

Thanks

+1  A: 

You can check for ContentType header in the Response's headers, primarily all text types begin with "text/*" like "text/html", "text/xml" etc etc, however here is a list of content types that can be useful. "application/javascript" etc are also text based but they are in different category.

Content Types

Akash Kava
Greg
so in fact it's really just the pseudo code I'm after, so how the decision branches would look for a generic file download method. E.g. how the following checks comes together:- content-type check: binary OR text- content-encoding check: uncompressed OR gzip
Greg
+1  A: 

Does the answer to this question http://stackoverflow.com/questions/678547/does-nets-httpwebresponse-uncompress-automatically-gziped-and-deflated-response give you what you want?

feroze