c# - 为什么我在使用 IPv6 URI 时得到 'System.UriFormatException: Invalid URI: Invalid port specified.'?

标签 c# ftp uri ipv6

为什么 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/

相关文章:

java - Apache Camel FTP 550 在 Linux 中删除文件时出错

android - 捕获图像后,我无法在 imageview 上显示它,除非我将它保存为位图形式。我需要以 Uri 形式保存它

android - 无法将位图转换为 Uri

c# - SqlDataReader:将 varbinary 读入字节数组

ftp - 如何从 Aptana Studio 3 连接到远程主机

c# - 使用 C# 通过套接字发送和接收图像

visual-studio - 是否可以让 nant 在 Web 应用程序项目上运行发布

.net - 从字符串验证 Uri

c# - itextsharp 测量 block 宽度/高度

c# - 如何从 powerpoint 中读取数据