[英]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)}
您的 URL 字符串包含零宽度空格字符(Unicode 字符代码 U+200B)。 您看不到它们,因为它们没有/零宽度。 [1]
具体来说,零宽度空格字符位于 url 字符串中的这些位置,用星号 (*) 标记:
https://api-dev.xxx.com.tr:9280*/order*/02357063/status
我不知道您是如何设法将这些字符放入 url 字符串中的,但具体来说,这些零宽度空格字符中的第一个是您遇到的错误的原因。 您会注意到,第一个零宽度空格字符紧跟在端口号之后,这对 URL 无效。 URL 中的权限后允许的唯一字符(在您的情况下,权限是服务器名称和端口号)是/
表示路径跟随, ?
表示后面跟着一个查询,或者#
表示后面跟着一个 URL 片段。
订单后的第二个零宽度空格字符正好位于 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直接输入这样的字符(不支持 ALT+Numpad 技术......)。
[1]您可以借助 Notepad++ 使这些零宽度空格字符可见,例如:在 Notepad++ 中打开一个新的空 UTF-8 或 UTF-16 文档。 然后将问题中的 URL 字符串复制并粘贴到 Notepad++ 中的该文本文档中。 然后将 Notepad++ 中文本文档的编码改为 ANSI,以前不可见的零宽度空格字符变为可见的问号或一堆“垃圾”字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.