简体   繁体   English

为什么我会收到'System.UriFormatException:无效的URI:指定的端口无效。' 使用IPv6 URI时?

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

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

Throw this exception? 抛出这个例外?

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

From RFC 2732 : 来自RFC 2732

To use a literal IPv6 address in a URL, the literal address should be enclosed in "[" and "]" characters. 要在URL中使用文字IPv6地址,文字地址应包含在“[”和“]”字符中。

For example, this works fine: 例如,这工作正常:

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

If you want to specify the port, it needs to be outside the square brackets: 如果要指定端口,则需要在方括号外:

var uri = new Uri("ftp://[1111:2222:3333::43]:100/testing/1kb.zip");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.UriFormatException:无效的URI:指定了无效的端口。 在C#中 - System.UriFormatException : Invalid URI: Invalid port specified. in c# System.UriFormatException:无效的URI:URI为空 - System.UriFormatException: Invalid URI : The URI is Empty System.UriFormatException:'无效的URI:Uri方案太长。 - System.UriFormatException: 'Invalid URI: The Uri scheme is too long.' 漏洞? System.UriFormatException:无效的 URI:URI 方案无效 - Bug? System.UriFormatException: Invalid URI: The URI scheme is not valid WatiN-故障:System.UriFormatException:无效的URI:无法解析主机名 - WatiN - Failure: System.UriFormatException : Invalid URI: The hostname could not be parsed 使用 ipv6 地址连接到使用 HttpClient 的服务器(使用 ipv6 地址定义 URI)修复 - Invalid URI: Invalid port specified) - Using ipv6 address to connect to a server using HttpClient (using ipv6 address to define URI) Fixing - Invalid URI: Invalid port specified) Microsoft.AspNetCore.SpaProxy 6.0.1 - ASPNETCORE_HOSTINGSTARTUPASSEMBLIES - System.UriFormatException:无效的 URI:URI 为空 - Microsoft.AspNetCore.SpaProxy 6.0.1 - ASPNETCORE_HOSTINGSTARTUPASSEMBLIES - System.UriFormatException: Invalid URI: The URI is empty WCF发现:System.UriFormatException使用带通配符的URI创建ServiceHost(*) - WCF Discovery: System.UriFormatException creating ServiceHost with a URI with a wildcard (*) 启动时出现“无效的URI:指定了无效的端口” - “Invalid URI: Invalid port specified” at startup 无效的Uri:指定了无效的端口C# - Invalid Uri: invalid port specified C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM