I’m writing a post-build powershell script for an ASP.NET application which is going to download a playcanvas project using the Rest API, extract it and make it servable with the rest of the project’s contents.
I would like this to run with no dependencies on tools that aren’t pre-installed with windows.
Powershell has a command ‘Invoke-RestMethod’, an http client which could be used with the API like curl. When calling it on most Uris I get the output I expect:
PS C:\Users\josh.taylor> Invoke-RestMethod -Uri 'https://jsonplaceholder.typicode.com/posts' -Method GET
userId id title
------ -- -----
1 1 sunt aut facere repellat provident occaecati excepturi optio reprehenderit
1 2 qui est esse
...
Lots of content
But when calling it on any playcanvas website uri or API endpoint, e.g. with the following script
try {
Invoke-RestMethod -Uri 'https://playcanvas.com'
}
catch {
$_.Exception | Format-List -Force
}
It returns that the connection has closed:
Status : SendFailure
Response :
Message : The underlying connection was closed: An unexpected error occurred on a send.
Data : {}
InnerException : System.IO.IOException: Authentication failed because the remote party has closed the
transport stream.
at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
TargetSite : System.Net.WebResponse GetResponse(System.Net.WebRequest)
StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
HelpLink :
Source : Microsoft.PowerShell.Commands.Utility
HResult : -2146233079
Can anybody else replicate this?
I am also new to the forum, so I’m sorry if this has been placed in the wrong category.