How to combine URIs

前端 未结 5 1446
情话喂你
情话喂你 2020-12-15 17:54

I have two Uri objects passed into some code, one is a directory and the other is a filename (or a relative path)

var a = new Uri(\"file:///C:/Some/Dirs\");
         


        
5条回答
  •  星月不相逢
    2020-12-15 18:21

    This should do the trick for you:

    var baseUri = new Uri("http://www.briankeating.net");
    var absoluteUri = new Uri(baseUri, "/api/GetDefinitions");
    

    This constructor follow the standard relative URI rules so the / are important :

    • http://example.net + foo = http://example.net/foo
    • http://example.net/foo/bar + baz = http://example.net/foo/baz
    • http://example.net/foo/ + bar = http://example.net/foo/bar
    • http://example.net/foo + bar = http://example.net/bar
    • http://example.net/foo/bar/ + /baz = http://example.net/baz

提交回复
热议问题