簡體   English   中英

為什么我會收到'System.UriFormatException:無效的URI:指定的端口無效。' 使用IPv6 URI時?

[英]Why do I get 'System.UriFormatException: Invalid URI: Invalid port specified.' when using an IPv6 URI?

為什么這個var uri = new Uri("ftp://1111:2222:3333::43/testing/1kb.zip");

拋出這個例外?

System.UriFormatException:無效的URI:指定的端口無效。 在System.Uri.CreateThis(String uri,Boolean dontEscape,UriKind uriKind)

來自RFC 2732

要在URL中使用文字IPv6地址,文字地址應包含在“[”和“]”字符中。

例如,這工作正常:

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");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM