M
Mike
I am using PowerShell to download an XML file into a string using the
DownloadString(URI) method of System.Net.WebClient object. Sample
commands below:
$Result = $Null;
$WebClient = new-object System.Net.WebClient;
$WebClient.Encoding = [System.Text.Encoding]:efault;
$WebClient.Proxy = [System.Net.WebRequest]:efaultWebProxy;
$WebClient.Proxy.Credentials =
[System.Net.CredentialCache]:efaultCredentials;
$Result = $WebClient.DownloadString("http://www.thomas-krause.de/
weblogs/elcaroop/rss.xml");
$Result | out-file "D:\DownloadString.xml";
This works as expected and the content of the original file seems to
be exactly the same as the downloaded file. The issue I am having is
that the file retrieved using $WebClient.DownloadString is
approximately twice the size of the original file (downloaded by doing
a "Save Target As..." when right clicking on the URL).
Can anyone explain why this is happening?
I have tried changing the System.Text.Encoding setting to all 7 types
that are available, some of them then give the correct file size that
I expect but the data is modified, while others give me the data that
I expect but not the file size that I expect.
The $webClient.DownloadFile("http://www.thomas-krause.de/weblogs/
elcaroop/rss.xml", "D:\DownloadedFile.xml");
method works fine for me and I get the exact data and file size as the
original but I would perfer to use DownloadString to avoid working
with local copies of the file.
Mike
DownloadString(URI) method of System.Net.WebClient object. Sample
commands below:
$Result = $Null;
$WebClient = new-object System.Net.WebClient;
$WebClient.Encoding = [System.Text.Encoding]:efault;
$WebClient.Proxy = [System.Net.WebRequest]:efaultWebProxy;
$WebClient.Proxy.Credentials =
[System.Net.CredentialCache]:efaultCredentials;
$Result = $WebClient.DownloadString("http://www.thomas-krause.de/
weblogs/elcaroop/rss.xml");
$Result | out-file "D:\DownloadString.xml";
This works as expected and the content of the original file seems to
be exactly the same as the downloaded file. The issue I am having is
that the file retrieved using $WebClient.DownloadString is
approximately twice the size of the original file (downloaded by doing
a "Save Target As..." when right clicking on the URL).
Can anyone explain why this is happening?
I have tried changing the System.Text.Encoding setting to all 7 types
that are available, some of them then give the correct file size that
I expect but the data is modified, while others give me the data that
I expect but not the file size that I expect.
The $webClient.DownloadFile("http://www.thomas-krause.de/weblogs/
elcaroop/rss.xml", "D:\DownloadedFile.xml");
method works fine for me and I get the exact data and file size as the
original but I would perfer to use DownloadString to avoid working
with local copies of the file.
Mike