WebClient.DownloadString Method (String)
Assembly: System (in system.dll)
Parameters
- address
A String containing the URI to download.
Return Value
A String containing the requested resource.| Exception type | Condition |
|---|---|
| The URI formed by combining BaseAddress and address is invalid. -or- An error occurred while downloading the resource. |
|
| The method has been called simultaneously on multiple threads. |
This method retrieves the specified resource. After it downloads the resource, the method uses the encoding specified in the Encoding property to convert the resource to a String. This method blocks while downloading the resource. To download a resource and continue executing while waiting for the server's response, use one of the DownloadStringAsync methods.
If the BaseAddress property is not an empty string ("") and address does not contain an absolute URI, address must be a relative URI that is combined with BaseAddress to form the absolute URI of the requested data. If the QueryString property is not an empty string, it is appended to address.
This method uses the RETR command to download an FTP resource. For an HTTP resource, the GET method is used.
Note: |
|---|
| This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing. |
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.I am using the above to try and check if websense is running.
So, running the following script SHOULD return TRUE
$source = "http:\\www.playboy.com"
$wc = new-object system.net.webclient
$content = $wc.DownloadString($source)
$content -match "Blocked"
The problem I am having it that the script errors with, "
Exception calling "DownloadString" with "1" argument(s): "The underlying connection was closed: An unexpected error occurred on a receive."
At :line:3 char:29
+ $content = $wc.DownloadString <<<< ($source)
In fact, it errors on any site that is blocked (xdrive). When I plug in a valid site, it runs fine.
Any ideas?
Thanks in advance for your help,
Alan
--------------------------------------------------------------------------------------------------------------------------------------
I have blocked xbox.com
to test websense blocking, see script below
$source = "http://www.xbox.com"
$wc = new-object system.net.webclient
$content = $wc.DownloadString($source)
$content -match "Blocked"
- 7/2/2009
- wallacefalan
- 8/23/2011
- epoh
- 8/23/2011
- epoh
This example will cause the page www.microsoft.com to be downloaded and displayed in Powershell
$webClient = new-object system.net.webclient
$webPage = $webClient.downloadstring(" http://www.microsoft.com ")
$webPage
- 12/22/2006
- EwanN
Note: