I’m trying to access a URL of a network switch to get some serial number info and what not. The URL for the switch is this:
hxxp://192.168.0.1/wcd?{DeviceBasicInfo}
In the browser this returns XML. Alright sounds easy enough, I run through powershell command like so:
Invoke-Webrequest “hxxp://192.168.0.1/wcd?{DeviceBasicInfo}”
Did not get the expected result. I powered up Fiddler to check and it’s encoding the curly braces { }. So the resulting URL is:
hxxp://192.168.0.1/wcd?%7BDeviceBasicInfo%7D
Putting that encoded result in a browser I get the same generic error result as powershell. The switch needs to have the { } braces in the URL for it to work. I looked at the URI constructor in C# just to be curious and they do have one with a flag with dontEscape boolean but that’s been obsoleted (here).
Has anyone ever encountered this situation before?
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
URL encoding of special characters is an important part of the whole system. The browsers deal with it fine just like everything else. Seems your device is the problem here, not accepting/knowing how to handle the encoded URL.
Just look at what google shows you searching with this URL
That work? Obsolete and deprecated don’t necessarily mean unavailable. If you ever want to know about what overloads are available, just provide the method without parenthesis. It will list all the Overloads for that method/constructor
[uri]::new
OverloadDefinitions
-------------------
uri new(string uriString)
uri new(string uriString, bool dontEscape)
uri new(uri baseUri, string relativeUri, bool dontEscape)
uri new(string uriString, System.UriKind uriKind)
uri new(uri baseUri, string relativeUri)
uri new(uri baseUri, uri relativeUri)