[英]Why do I get 'System.UriFormatException: Invalid URI: Invalid port specified.' when using an IPv6 URI?
Why does this var uri = new Uri("ftp://1111:2222:3333::43/testing/1kb.zip");
为什么这个
var uri = new Uri("ftp://1111:2222:3333::43/testing/1kb.zip");
Throw this exception? 抛出这个例外?
System.UriFormatException: Invalid URI: Invalid port specified.
System.UriFormatException:无效的URI:指定的端口无效。 at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
在System.Uri.CreateThis(String uri,Boolean dontEscape,UriKind uriKind)
To use a literal IPv6 address in a URL, the literal address should be enclosed in "[" and "]" characters.
要在URL中使用文字IPv6地址,文字地址应包含在“[”和“]”字符中。
For example, this works fine: 例如,这工作正常:
var uri = new Uri("ftp://[1111:2222:3333::43]/testing/1kb.zip");
If you want to specify the port, it needs to be outside the square brackets: 如果要指定端口,则需要在方括号外:
var uri = new Uri("ftp://[1111:2222:3333::43]:100/testing/1kb.zip");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.