PowerShell | HTTP Request/Response

[string]$url="http://IWantToPostHere.com/something"

[System.Net.httpWebRequest] $req = [System.Net.webRequest]::create($url)
$req.method = "POST"
$req.ContentType = "application/x-www-form-urlencoded"
$req.ContentLength = $buffer.length
$req.TimeOut = 5000
$reqst = $req.getRequestStream()
$reqst.write($buffer, 0, $buffer.length)
$reqst.flush() #writes stuff overboard
$reqst.close()

#this code is not catched, errors will not show pretty, but you know whats happening
[System.Net.httpWebResponse] $res = $req.getResponse()
$resst = $res.getResponseStream()
$sr = new-object IO.StreamReader($resst)
$result = $sr.ReadToEnd()
write-host "`nHTTP Response is " $result



http://msdn.microsoft.com/en-us/magazine/cc507642.aspx

Comments

Popular posts from this blog

Breaking down document locking in SharePoint

Working around X-Frame-Options for iframes

Document ID not being generated