How to remove the port number from a url string

前端 未结 8 615
清酒与你
清酒与你 2021-02-02 04:57

I have the following code snippet:

string tmp = String.Format(\"

        
8条回答
  •  抹茶落季
    2021-02-02 05:50

    UriBuilder u1 = new UriBuilder( "http://www.example.com:80/dir/?query=test" );
    u1.Port = -1;
    string clean = u1.Uri.ToString();
    

    Setting the Port property to -1 on UriBuilder will remove any explicit port and implicitly use the default port value for the protocol scheme.

提交回复
热议问题