I use HttpClient.GetAsync() method. I have a list of categories and want to pass it in query string.
var categories = new List<int>() {1,2};
How can I pass List<int>/List<string> in query string?
For example, https://example.com/api?categories=1,2
Of course, can use foreach and StringBuilder. But maybe there is a better way to do this?
For example, work with .PostAsync() and json content very convenient:
var categories = new List<int>() {1,2}; //init List
var parametrs = new Dictionary<string, object>();
parametrs.Add("categories", categories);
string jsonParams = JsonConvert.SerializeObject(parametrs); // {"categories":[1,2]}
HttpContent content = new StringContent(jsonParams, Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync(new Uri("https://example.com"), content);
P.S. I work with Windows Phone 8.
StringBuilder, just usestring.Join(",", categories).