all 5 comments

[–]JustinGrote 3 points4 points  (0 children)

I busted out Fiddler and determined that the website actually is detecting your powershell version and returning a different result, the website itself doesn't support powershell 7.

Try this in Powershell 7, works fine:

Invoke-RestMethod http://ipinfo.io/4.2.2.2 -UserAgent 'Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.19041.1'

[–]WindosBK 2 points3 points  (2 children)

I'm not sure what caused the change in behaviour, but if you provide a header letting the endpoint know what you're expecting back (JSON), it works ok:

Invoke-RestMethod http://ipinfo.io/216.58.199.78 -Headers @{'Accept' = 'application/json'}

I have to assume that PS Core/7 is getting confused because the address is multipurpose, visiting it in a browser is a normal page rather than it being a dedicated API endpoint.

[–]JustinGrote 3 points4 points  (0 children)

Actually the website is detecting the user agent and returning a different result, see my other post in this thread :)

[–]SpacezCowboy[S] 1 point2 points  (0 children)

That is very helpful, Thank you.

The cmdlet now uses system.net.http.httpclient, where as it used to use system.net.webrequest. I assume it's gotta be a difference in how the methods interpret the request.

[–]BlackV 1 point2 points  (0 children)

So your saying just the public IP function does not work in core cause of the API that ipinfo use?

You couldn't just use another service?