1

I have been following this link: Build query string for System.Net.HttpClient get

but my situation was a little different and was not sure what the best approach would be. As of now I am thinking about going with a for loop but figured there might be a better approach.I have a list of parameters. I thought about just for looping over the list but that would make it where the querystring would be "?foo=1?foo=2" See below example as to what I am looking for and what I have so far

var query = HttpUtility.ParseQueryString(string.Empty);
List<String> foos = ...
query["foo"] = "1";
string queryString = query.ToString()
//Expected query string to be ?foo=1&foo=2
JacobTStaggs
  • 107
  • 10

1 Answers1

0

Try Add method on NameViewCollection

With Add method you can add multiple values for a single key.

        var qs = HttpUtility.ParseQueryString(string.Empty);
        qs.Add("foo", "1");
        qs.Add("foo", "2");

qs.ToString(); would give you foo=1&foo=2

Suresh
  • 4,091
  • 28
  • 35