Closed
Description
Description
- The Uri constructor cannot parse http://hostname:port/ when hostname is * or +, ie, http://*:9999/ or http://+:9999 will cause an exception to be thrown.
httpListener = new HttpListener();
string url = "http://*:1234/";
Uri uri = new Uri(url);
// do something here... then pass the url (not uri) to the httpListener
httpListener.Prefixes.Add(url);
-
On the "new Uri(url)" line, the following exception occurred
System.UriFormatException
HResult=0x80131537
Message=Invalid URI: The hostname could not be parsed.
Source=System.Private.Uri
StackTrace:
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString)
at HttpListenerSegments.Program..ctor() in K:\Development\CSharp\HttpListenerSegments\Program.cs:line 18
at HttpListenerSegments.Program.Main(String[] args) in K:\Development\CSharp\HttpListenerSegments\Program.cs:line 79 -
The Uri constructor should parse * or + into the DnsSafeHost, Host and IdnHost properties/fields (and whatever fields that currently holds the hostname).
-
.NET Core 2.1
-
Windows 11
-
x64