I play with the RESTful API and with the Firefox RESTClient plugin everything is fine. I can easily request the API.
However, when I try to connect the same API call in powershell, it does not work!
I tried the following code from various other posts that should eliminate certificate issues, but I still can't get this to work:
# This nugget should help me to get around any self-signed certificate issues I believe $netAssembly =[Reflection.Assembly]::GetAssembly([System.Net.Configuration.SettingsSection]) if($netAssembly) { $bindingFlags = [Reflection.BindingFlags] "Static,GetProperty,NonPublic" $settingsType = $netAssembly.GetType("System.Net.Configuration.SettingsSectionInternal") $instance = $settingsType.InvokeMember("Section", $bindingFlags, $null, $null, @()) if($instance) { $bindingFlags = "NonPublic","Instance" $useUnsafeHeaderParsingField = $settingsType.GetField("useUnsafeHeaderParsing", $bindingFlags) if($useUnsafeHeaderParsingField) { $useUnsafeHeaderParsingField.SetValue($instance, $true) } } } [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} $headers = @{"AUTHORIZATION"="Basic YWRtaW46Y2xvdWQ="}
I cannot replicate this using Powershell V3 Invoke-RestMethod, and wondered if anyone could share sample code to access an HTTPS server that has a self-signed certificate, and also use basic authorization.
Error message:
PS C:\Users\landg> C:\Users\landg\Documents\Scripts\CSA API\CSA_API_DEMO_take2.ps1 Invoke-RestMethod : Unable to connect to the remote server At C:\Users\landg\Documents\Scripts\CSA API\CSA_API_DEMO_take2.ps1:31 char:1 + Invoke-RestMethod -Uri https://192.168.5.3:8444/csa/rest/login/CSA-Provider/admi ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Grazzer
source share