Author Posts

December 5, 2016 at 5:54 am

I have a https website running say https://localhost:1234/HelloService/ . I have to write a powersheel script which will get connected to this website and consume the data. I could do using http following some tutorials, but i am unable to do it for https.

December 5, 2016 at 10:13 pm

Please share some example code and error messages.

December 6, 2016 at 4:11 am

add-type @"
   using System.Net;
   using System.Security.Cryptography.X509Certificates;
   public class TrustAllCertsPolicy : ICertificatePolicy 
    {
      public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate,WebRequest request, int certificateProblem)        
        {
           return true;
        }
    }
"@

[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$result = Invoke-WebRequest -Uri "https://localhost:1234/HelloService/ "

December 6, 2016 at 4:13 am

Error :

Invoke-WebRequest : The request was aborted: Could not create SSL/TLS secure channel.
At D:\Untitled1.ps1:15 char:11
+ $result = Invoke-WebRequest -Uri "https://localhost:1234/HelloService/...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

December 6, 2016 at 6:27 pm

Can you browse to the URL using HTTPS without getting any errors? That's a fairly generic error but I would suspect a problem with either the certificate or the webserver.

Edit: Just had a thought, won't you always get a certificate error if you go to localhost?