Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Http Post with List and string

$
0
0

Hi,

I need to do an http post to my api with 3 parameters, 2 of them are a string but the last needs to be a list of strings. I cant seem to add just the list to my httpcontent. I also cant just convert it to Json because the api will give an error back.

List<string> allCalendars = new List<string>() { "cal1", "cal2", "cal3" };

            HttpClient client = new HttpClient();
            var postData = new List<KeyValuePair<string, string>>();
            postData.Add(new KeyValuePair<string, string>("type", "abc"));
            postData.Add(new KeyValuePair<string, string>("deviceId", "dsfdsf54dfd"));
            postData.Add(new KeyValuePair<string, string>("calendars", allCalendars));
            HttpContent content = new FormUrlEncodedContent(postData);

HttpResponseMessage res = await client.PostAsync("url", content);

            string r = await res.Content.ReadAsStringAsync();

Viewing all articles
Browse latest Browse all 58056

Trending Articles