Powershell Http post request <p>Read over the stackoverflow for the answer, still can't find what causing this..</p> <p>Trying to connect and send a POST request using powershell, and getting "unable to connect to remote server" error. Tried 3 different dummy servers like <a href="http://posttestserver.com/post.php" rel="nofollow">http://posttestserver.com/post.php</a></p> <p>Script:</p> <pre><code>Get-ExecutionPolicy [string]$url = "http://posttestserver.com/post.php" function Execute-HTTPPostCommand() { param([string]$target = $null) #$username = "administrator" #$password = "mypass" $webRequest = [System.Net.WebRequest]::Create($target) $webRequest.ContentType = "text/html" $post = "abcdefg" $PostStr = [System.Text.Encoding]::UTF8.GetBytes($Post) $webrequest.ContentLength = $PostStr.Length $webRequest.ServicePoint.Expect100Continue = $false #$webRequest.Credentials = New-Object System.Net.NetworkCredential -ArgumentList $username, $password #$webRequest.PreAuthenticate = $true $webRequest.Method = "POST" try { $requestStream = $webRequest.GetRequestStream() } catch { write-host $_.Exception } $requestStream.Write($PostStr, 0,$PostStr.length) $requestStream.Close() [System.Net.WebResponse]$resp = $webRequest.GetResponse(); $rs = $resp.GetResponseStream(); [System.IO.StreamReader]$sr = New-Object System.IO.StreamReader -argumentList $rs; [string]$results = $sr.ReadToEnd(); return $results; } Execute-HTTPPostCommand $url [System.GC]::Collect() </code></pre>