【问题标题】:Why do I get 'System.UriFormatException: Invalid URI: Invalid port specified.' when using an IPv6 URI?为什么我会收到“System.UriFormatException:无效的 URI:指定的端口无效。”使用 IPv6 URI 时?
【发布时间】:2013-12-05 14:32:31
【问题描述】:

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

抛出这个异常?

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

【问题讨论】:

    标签: c# ftp uri ipv6


    【解决方案1】:

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

    【讨论】:

    • 乔恩,我读到了这个stackoverflow.com/a/1984225/22656,我很困惑为什么以下是错误的 new Uri("Prera​​k/Kaushik/SomeResource");谢谢。
    • @Prera​​kK:这听起来应该是一个新问题。特别是,它与这个关于 IPv6 表示的问题无关。 (但简而言之:您还没有在其中指定 URI 方案名称。)
    猜你喜欢
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-03
    • 1970-01-01
    • 2011-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多