0

Is it possible to make a downloadstring() and using gzip-compression, if the server is accepting this?

$wc = New-Object System.Net.WebClient
$wc.Encoding = [System.Text.Encoding]::UTF8
$wc.Headers.Add("User-Agent: Other")

$qc = $wc.Downloadstring($url)

Does anyone know the correct Headers.Add or what do we have to add?

030
  • 10,842
  • 12
  • 78
  • 123
Florian
  • 1
  • 3

1 Answers1

2

Try this:

$url = "http://www.somewebsite.com/"
$wc = New-Object System.Net.WebClient
$wc.Headers.Add([System.Net.HttpRequestHeader]::AcceptEncoding, "gzip")
$wc.Headers.Add("User-Agent: Other")
$qc = $wc.Downloadstring($url)

Alternatively you can try and use DownloadFile method to see if this yields an expected result:

$wc.DownloadFile($url, "c:\temp\dump.txt" )

If there are errors then update your question to include them.

Raf
  • 9,681
  • 1
  • 29
  • 41
  • This works perfekctly and downloads the Content as an gzip - String (or file with DownloadFile() ). Do you also know the way to decompress the $qc - variable as an normal "string"? – Florian Aug 06 '14 at 14:09
  • Most likely you will have to use .Net GzipStream class but it's best if you post it as a separate question. – Raf Aug 06 '14 at 14:20