[ACCEPTED]-Combining URIs and Paths-web-services

Accepted answer
Score: 40

Don't use the Uri object, use a UriBuilder - it copes 2 way better with missing slashes

So

Uri apiUri = new Uri("http://www.r-s.co.uk/eproxy.php");
string methodPath = "/char/SkillIntraining.xml.aspx";

System.UriBuilder uriBuilder = new System.UriBuilder(apiUri);
uriBuilder.Path += methodPath;

Console.WriteLine(uriBuilder.Uri.ToString());

works as 1 expected and produces http://www.r-s.co.uk/eproxy.php/char/SkillIntraining.xml.aspx

Score: 10

Add a trailing "/" to apiUri, and remove 1 the leading "/" from method.Path:

Uri apiUri = new Uri("http://www.r-s.co.uk/eproxy.php/");
string path = "char/SkillIntraining.xml.aspx";
Uri uri = new Uri(apiUri, path);
Console.WriteLine(uri.ToString());

Will print:

http://www.r-s.co.uk/eproxy.php/char/SkillIntraining.xml.aspx

More Related questions