简体   繁体   English

C# 无效 URI:指定的端口无效

[英]C# Invalid URI: Invalid port specified

new Uri("https://api-dev.xxx.com.tr:9280​/order​/02357063/status")' 
threw an exception of type 'System.UriFormatException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233033
    HelpLink: null
    InnerException: null
    Message: "Invalid URI: Invalid port specified."
    Source: "System.Private.Uri"
    StackTrace: 
   "at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)\r\n
    at System.Uri..ctor(String uriString)"
TargetSite: {Void CreateThis(System.String, Boolean, System.UriKind, System.UriCreationOptions ByRef)}

Your URL string contains zero-width space characters (Unicode character code U+200B).您的 URL 字符串包含零宽度空格字符(Unicode 字符代码 U+200B)。 You can't see them because they have no/zero width.您看不到它们,因为它们没有/零宽度。 [1] [1]

Specifically, the zero-width space characters are at these positions in your url string, marked with asterisks (*):具体来说,零宽度空格字符位于 url 字符串中的这些位置,用星号 (*) 标记:

https://api-dev.xxx.com.tr:9280*/order*/02357063/status

I don't know how you managed to get those characters into your url string, but specifically the first of those zero-width space characters is responsible for the error you got.我不知道您是如何设法将这些字符放入 url 字符串中的,但具体来说,这些零宽度空格字符中的第一个是您遇到的错误的原因。 As you'll notice, the first zero-width space characters follows directly after the port number, which is not valid for URLs.您会注意到,第一个零宽度空格字符紧跟在端口号之后,这对 URL 无效。 The only characters allowed after an authority (the authority in your case would be the server name together with the port number) in a URL are / indicating that a path follows, ? URL 中的权限后允许的唯一字符(在您的情况下,权限是服务器名称和端口号)是/表示路径跟随, ? indicating that a query follows, or # indicating that an URL fragment follows.表示后面跟着一个查询,或者#表示后面跟着一个 URL 片段。

The second zero-width space character after order right there smack in the middle of the url path -- although unrelated to the error you got -- is also problematic, as it quite likely will prevent the server from parsing the url path correctly.订单后的第二个零宽度空格字符正好位于 url 路径的中间——尽管与您遇到的错误无关——也是有问题的,因为它很可能会阻止服务器正确解析 url 路径。

The solution: Type the URL string manually anew (don't do copy&paste; type the url string completely manually), because this way you should not get unwanted zero-width space characters or other nasties in your URL string simply because you can't directly type in such characters (the ALT+Numpad technique not withstanding...). The solution: Type the URL string manually anew (don't do copy&paste; type the url string completely manually), because this way you should not get unwanted zero-width space characters or other nasties in your URL string simply because you can't直接输入这样的字符(不支持 ALT+Numpad 技术......)。


[1] You can make these zero-width space characters visible with the help of Notepad++, for example: Open a new empty UTF-8 or UTF-16 document in Notepad++. [1]您可以借助 Notepad++ 使这些零宽度空格字符可见,例如:在 Notepad++ 中打开一个新的空 UTF-8 或 UTF-16 文档。 Then copy&paste the URL string right from your question into that text document in Notepad++.然后将问题中的 URL 字符串复制并粘贴到 Notepad++ 中的该文本文档中。 Then change the encoding of the text document in Notepad++ to ANSI, and the formerly invisible zero-width space characters become visible either as question marks or as a bunch of "garbage" characters.然后将 Notepad++ 中文本文档的编码改为 ANSI,以前不可见的零宽度空格字符变为可见的问号或一堆“垃圾”字符。

暂无
暂无

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

相关问题 无效的Uri:指定了无效的端口C# - Invalid Uri: invalid port specified C# System.UriFormatException:无效的URI:指定了无效的端口。 在C#中 - System.UriFormatException : Invalid URI: Invalid port specified. in c# 无效的URI:在指定带有端口号的URL时在C#中指定的无效端口,如http:// localhost:8080 / jasperserver / rest - Invalid URI: Invalid port specified in C# on specifying URL with port number in it like http://localhost:8080/jasperserver/rest 启动时出现“无效的URI:指定了无效的端口” - “Invalid URI: Invalid port specified” at startup 无效的URI:指定了无效的端口/无法解析主机名 - Invalid URI: Invalid port specified / The hostname could not be parsed 指定的演员表无效 - C# - Specified cast is invalid - C# C# 删除 Azure Blob - 无效的 URI - C# Delete Azure Blob - Invalid Uri 无效的URI:当url具有多个冒号时指定的端口无效 - Invalid URI: Invalid port specified when url has more than one colon 使用 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) 为什么我会收到'System.UriFormatException:无效的URI:指定的端口无效。' 使用IPv6 URI时? - Why do I get 'System.UriFormatException: Invalid URI: Invalid port specified.' when using an IPv6 URI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM