为什么 var uri = new Uri("ftp://1111:2222:3333::43/testing/1kb.zip");
抛出这个异常?
System.UriFormatException: Invalid URI: Invalid port specified. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
最佳答案
来自 RFC 2732 :
To use a literal IPv6 address in a URL, the literal address should be enclosed in "[" and "]" characters.
例如,这工作正常:
var uri = new Uri("ftp://[1111:2222:3333::43]/testing/1kb.zip");
如果要指定端口,需要在方括号外:
var uri = new Uri("ftp://[1111:2222:3333::43]:100/testing/1kb.zip");
关于c# - 为什么我在使用 IPv6 URI 时得到 'System.UriFormatException: Invalid URI: Invalid port specified.'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20402684/