1

I am trying to run citrix api through powershell but it is giving me error

The underlying connection was closed: An unexpected error occurred on a send.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls
$Citrixheaders = @{'Citrix-CustomerId'=$customerId;'Authorization'=$GLOBAL:XDAuthToken}
$url = "https://api-us.cloud.com/monitorodata/Applications"
(Invoke-RestMethod $url -Headers $Citrixheaders  -UseBasicParsing -Method GET -ContentType "application/json" -Verbose -ErrorAction Stop).value

This is the code I am running.

The same api with the headers returning value from Postman

I have checked internet and tried below codes but it is also not working.

#1

$code =@"
public class SSLHandler
{
    public static System.Net.Security.RemoteCertificateValidationCallback GetSSLHandler()
    {
        return new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => {return true; });
    }
}
"@
Add-type -TypeDefinition $code
[Net.ServicePointManager]::ServerCertificateValidationCallback = [SSLHandler]::GetSSLHandler()

[Net.Servicepointmanager]::Expect100Continue = $true

#2

[Net.Servicepointmanager]::ServerCertificateValidationCallback = $true
[Net.Servicepointmanager]::Expect100Continue = $true

I am not sure what to do next, Please give your suggestion

Jithin Jeffry
  • 13
  • 1
  • 4

0 Answers0