Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using namespace System
using namespace System.Net
using namespace System.Text
using namespace System.IO
class Test
{
# Specify the URL to receive the request.
static Run([string[]]$arguments)
{
[HttpWebRequest]$request = [HttpWebRequest][WebRequest]::Create($arguments[0]);
# Set some reasonable limits on resources used by this request
$request.MaximumAutomaticRedirections = 4;
$request.MaximumResponseHeadersLength = 4;
# Set credentials to use for this request.
$request.Credentials = [CredentialCache]::DefaultCredentials;
[HttpWebResponse]$response = [HttpWebResponse]$request.GetResponse();
Write-Host ("Content length is {0}" -f $response.ContentLength);
Write-Host ("Content type is {0}" -f $response.ContentType);
# Get the stream associated with the response.
[Stream]$receiveStream = $response.GetResponseStream();
# Pipes the stream to a higher level stream reader with the required encoding format.
[StreamReader]$readStream = [StreamReader]::new($receiveStream, [Encoding]::UTF8);
Write-Host ("Response stream received.");
Write-Host ($readStream.ReadToEnd());
$response.Close();
$readStream.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.