In Xamarin Forms there is a native function called UriBuilder: it allow you to create a well-formed url. In my implementation, all parameters are in a Dictionary called parameters. Using Linq, I put in builder.Query only the parameters with a value.
UriBuilder builder = new UriBuilder(yourUrl); Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("reference", Reference); parameters.Add("param1", Param1); builder.Query = string.Join("&", parameters.Where(p => !string.IsNullOrWhiteSpace(p.Value)) .Select(p => string.Format("{0}={1}", Uri.EscapeDataString(p.Key), Uri.EscapeDataString(p.Value)))); return builder.ToString();
Happy coding!