locked
Invoke-Webrequest throwing the error "The underlying connection was closed: An unexpected error occurred on a send" RRS feed

  • Question

  • Hello All,

    I have this very simple Powershell 5.0 script that am struggling to make it work. Gone through numerous posts in this forum but none of them could help me in resolving the issue.

    I am trying to make use of the "Invoke-WebRequest" cmdlet to make a GET call to one of our firm's internal URL but when executed I keep receiving the below error .

    Supply values for the following parameters:
    Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
    At D:\Work\PowerShell Scripts\InvokeWebequest test.ps1:12 char:6
    + $r = Invoke-WebRequest -Uri $uri -Method GET -Credential $mycredentia ...
    +      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
        + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestComm

    The lines of my script are as pasted below .

    $uri = "http://wiki.domain.com"
    $mycredentials = Get-Credential # At the time of script execution, the correct username and password are entered
    $r = Invoke-WebRequest -Uri $uri -Method GET -Credential $mycredentials -SessionVariable websession

    Note: The Url in question is Siteminder protected and when accessed directly through browser doesn't prompt for login.


    • Edited by PATH2Power Thursday, June 1, 2017 2:30 AM
    Thursday, June 1, 2017 2:26 AM

All replies