Created
December 7, 2019 13:23
-
-
Save IISResetMe/158837b9c924907054fe924d3f1de709 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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