gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:37:50 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com