开发者

why the following fails

开发者 https://www.devze.com 2023-01-30 05:23 出处:网络
Uri test = new Uri(\"http%3A%2F%2F100.100.1.1%3A8080\"); An unhandled exception of type \'System.UriFormatException\' occurred in System.开发者_C百科dll
 Uri test = new Uri("http%3A%2F%2F100.100.1.1%3A8080");

An unhandled exception of type 'System.UriFormatException' occurred in System.开发者_C百科dll

Additional information: Invalid URI: The format of the URI could not be determined.

Anyone know why I cannot pass in a URL encoded string to the constructor of Uri?


Do not escape it and try using http://100.100.1.1:8080.


The Uri Constructor requires the String to be a valid RFC2396 URI. There's this Uri.CheckSchemeName Method to check if your passed URI is valid.


Are you missing a % before the second 2F? Try passing the string through a URL un-encoder and make sure the result is what you expected.

0

精彩评论

暂无评论...
验证码 换一张
取 消