Skip to content

Uri constructor cannot parse http://hostname:port/ when hostname is * or + #77464

Closed
@chuacw

Description

@chuacw

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions