Solved: Send request to localhost/app/page (IIS) -- SSL/TLS error

Microsoft Windows
Post Reply
1011010101010111001
Posts: 4
Joined: 2021-Oct-28, 4:06 pm

Solved: Send request to localhost/app/page (IIS) -- SSL/TLS error

Post by 1011010101010111001 »

Hello, I'm needing to get the version number of the web app that's currently running on IIS instance.

There is a text file that contains the version information located at:
D:\Program Files\vendor\application name\version number-application name\web\the *.txt file.

That file can be accessed via: (http is forbidden)
https://localhost/application/the text file.txt

In order for me to get the version number so that I can add it to the path to the /web/ directory, I must know the version number... lol.

I thought I'd just have the PS script do one of these to get the version number from IIS and then continue on in my script:

Code: Select all

Invoke-RestMethod "https://localhost/application/the text file.txt"
But that results in this:

Code: Select all

Invoke-RestMethod : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
At line:1 char:1
And I don't know how to get around that, or if there is an entirely different method to reach https://localhost/application/the text file.txt. I'm open to any ideas.
Last edited by 1011010101010111001 on 2021-Nov-11, 8:54 pm, edited 1 time in total.
User avatar
Simon Sheppard
Posts: 50
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: Send request to localhost/app/page (IIS)

Post by Simon Sheppard »

If you try to retrieve https://localhost/application/
does that give you a default directory browsing list of the files?
https://docs.microsoft.com/en-us/iis/co ... torybrowse

If not, you may need to iterate through all the likely numbers, which may be very slow.
1011010101010111001
Posts: 4
Joined: 2021-Oct-28, 4:06 pm

Re: Send request to localhost/app/page (IIS)

Post by 1011010101010111001 »

Yep, directory browsing is on. port 80 will auto redirect to 443 one these machines. So I can't use http instead of https. Additionally I switched over to 'Invoke-WebRequest' and get the same results when I run it locally.

It's definitely an SSL hurdle thats in my way, I know how to program around this with Python but not with Powershell.
User avatar
Simon Sheppard
Posts: 50
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: Send request to localhost/app/page (IIS)

Post by Simon Sheppard »

so try something like this:

Code: Select all

$r=invoke-webrequest https://localhost/application/ -UseBasicParsing  
$r.Links |?{$_.href -match ".txt"} 
If that works, then you just need to parse out the most recent file and build a second invoke-webrequest with the right number.
https://stackoverflow.com/a/27945081/1720814
1011010101010111001
Posts: 4
Joined: 2021-Oct-28, 4:06 pm

Re: Send request to localhost/app/page (IIS)

Post by 1011010101010111001 »

Solution for SSL error with PS version 5

Code: Select all

#deal with SSL/TLS issues first
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;
    }
}
"@

$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
Post Reply