1

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

Greg
  • 34,042
  • 79
  • 253
  • 454
  • 2
    perhaps if you could show us the code you have so far? people don't generally like to just write your code for you – annakata Sep 27 '09 at 10:44
  • I just answered you on http://stackoverflow.com/questions/678547/does-nets-httpwebresponse-uncompress-automatically-gziped-and-deflated-response – Jader Dias Sep 28 '09 at 00:52

2 Answers2

1

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
  • 39,066
  • 20
  • 121
  • 167
  • perhaps the easiest way might be to download everything as if it is a binary file, but then check for content-encoding for gzip and uncompress these (i.e. rather than getting what files could be downloaded as a string & which as a binary file, and which are gzip'ed and require decompression and which aren't, just make it simpler)... – Greg Sep 27 '09 at 11:46
  • 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 Sep 27 '09 at 11:50
1

Does the answer to this question Does .NET's HttpWebResponse uncompress automatically GZiped and Deflated responses? give you what you want?

Community
  • 1
  • 1
feroze
  • 7,380
  • 7
  • 40
  • 57