简体   繁体   中英

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). You can't see them because they have no/zero width. [1]

Specifically, the zero-width space characters are at these positions in your url string, marked with asterisks (*):

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. As you'll notice, the first zero-width space characters follows directly after the port number, which is not valid for URLs. 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, ? indicating that a query follows, or # indicating that an URL fragment follows.

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.

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...).


[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++. Then copy&paste the URL string right from your question into that text document in 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM