Skip to content

Instantly share code, notes, and snippets.

@octan3
Created August 4, 2011 11:42
Show Gist options
  • Save octan3/1125011 to your computer and use it in GitHub Desktop.
Save octan3/1125011 to your computer and use it in GitHub Desktop.
PowerShell HTTP Cookie Catcher (WebRequest, SSL Certificate Validation Check, Expect 100)
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
[Net.ServicePointManager]::Expect100Continue = $false
$cc = new-object Net.CookieContainer
$req = [Net.WebRequest]::Create("https://www.example.com/service")
$req.CookieContainer = $cc
$req.Method = 'POST'
$req.Timeout = 5000
$req.ContentType = 'application/x-www-form-urlencoded'
$dataAr = [Text.Encoding]::GetEncoding("ISO-8859-1").GetBytes("ExamplePostData")
$rs = $req.GetRequestStream()
$rs.Write($dataAr, 0, $dataAr.length)
$rs.Close()
$req.GetResponse() | Out-Null
$cc.GetCookies($req.RequestUri) | % { if ($_.Name -eq 'ExampleCookie') { $exampleCookie = $_.Value } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment