public void ParseQueryTest() { UriBuilder uriBuilder = new UriBuilder("http://", "mccoysoftware.uk"); uriBuilder.Query = "Title=Mr&FirstName=Arthur&Surname=Dent"; NameValueCollection nvc = uriBuilder.ParseQuery(); Assert.AreEqual("Mr", nvc["Title"]); Assert.AreEqual("Arthur", nvc["FirstName"]); Assert.AreEqual("Dent", nvc["Surname"]); }
public static UriBuilder SetQueryParameters(this UriBuilder uri, NameValueCollection queryParameters) { var collection = uri.ParseQuery(); foreach (var name in queryParameters.AllKeys) { collection.Set(name, queryParameters[name]); } uri.Query = collection.AsKeyValuePairs().Select(pair => pair.Key == null ? pair.Value : pair.Key + "=" + pair.Value).ToString("&"); return(uri); }
public static IEnumerable <KeyValuePair <string, string> > GetQueryParams(this UriBuilder uri) { return(uri.ParseQuery().AsKeyValuePairs()); }