using System.Collections.Generic;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
public static void Main()
var url = string.Format("https://{0}",Guid.NewGuid().ToString("D"));
var exampleUri = new Uri(url);
var requestUri = QueryHelpers.AddQueryString(exampleUri.AbsoluteUri, new Dictionary<string,string>{
{ "myvar1", 123.ToString() },
{ "myvar2", "hello world" }
Console.WriteLine(requestUri);
var exampleUri2 = new Uri("https://example.com/some/path");
var requestUri2 = QueryHelpers.AddQueryString(exampleUri2.AbsoluteUri, new Dictionary<string,string>{
{ "myvar1", 123.ToString() },
{ "myvar2", "hello world" }
Console.WriteLine(requestUri2);
var builder = new UriBuilder
Path = "some/path/to/resource",
Query = QueryString.Create(new Dictionary<string, StringValues>
["val1"] = "hello world",
["val2"] = "second value",
["val3"] = 123.63f.ToString()
Console.WriteLine(builder.Uri.AbsoluteUri);