3

I am attempting to test a very simple powershell script to get/post data from an internal ticketing site. I am running into an issue that appears to be related to the SSL certificate needed. Can someone please help me understand what code I need to add to make this work?

Thanks

Error returned: Exception calling "GetResponse" with "0" argument(s): "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

Current Code:

 $url = "https://username:password@IPADDRESS/ticket"
 $command = get-content jsonfile.json

 $bytes = [System.Text.Encoding]::ASCII.GetBytes($command)
 $web = [System.Net.WebRequest]::Create($url)
 $web.Method = "POST"
 $web.ContentLength = $bytes.Length
 $web.ContentType = "application/json"
 $stream = $web.GetRequestStream()
 $stream.Write($bytes,0,$bytes.Length)
 $stream.close()

 $reader = New-Object System.IO.Streamreader -ArgumentList
 $web.GetResponse().GetResponseStream()
 $reader.ReadToEnd()
 $reader.Close()
floyd
  • 2,080
  • 4
  • 17
  • 19
  • 1
    See if this helps http://stackoverflow.com/questions/9917875/power-shell-web-scraping-ssl-tsl-issue/9918045#9918045 – Andy Arismendi Jul 24 '12 at 00:21
  • 1
    Thanks that did help. However, I soon discovered that Powershell v3 now has an Invoke-RestMethod cmdlet which does what I need. – floyd Jul 25 '12 at 23:27

1 Answers1

5

I was able to get the functionality that I needed out of the new Invoke-RestMethod cmdlet introduced in Powershell v3. This method allows you to include a certificate which I did and did not receive any errors.

Dante May Code
  • 11,177
  • 9
  • 49
  • 81
floyd
  • 2,080
  • 4
  • 17
  • 19