getting “Exception calling ”GetResponse" while getting cache size in kemp using powershell script

I am trying to get cache size from Kemp server using power shell script. Following is thew script I am using to do so. But keep getting "Exception calling "GetResponse" with "0" argument(s): "The underlying connection was closed: An unexpected error occurred on a send"

$uri = "https://10.0.0.1/access/get?param=cachesize"

$username = "bal" $password = "XXXXXXX" strong text

$secPw = ConvertTo-SecureString $password -AsPlainText -Force

$Credential = New-Object PSCredential -ArgumentList $username,$secPw

[System.Net.ServicePointManager]::Expect100Continue = $true [System.Net.ServicePointManager]::MaxServicePointIdleTime = 10000 [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} $request = [System.Net.HttpWebRequest]::Create($uri) $request.Credentials = $Credential

$response = $request.GetResponse() $response $stream = $response.GetResponseStream() if($response.contenttype -eq "text/xml") { $Encoding = [System.Text.Encoding]::GetEncoding("utf-8") $reader = New-Object system.io.StreamReader($stream, $Encoding) $result = $reader.ReadToEnd() $result if ($result.response.success) { if ([string]::IsNullOrEmpty($result.response.success.data)) { Write-Output $result.response.code } else { Write-output $result.response.success.data } } else { Write-Output $result.response } }

please guide what is causing this error. Not good in powershell.