Use KeyValuePair<string, object>
to put values and create or convert the list to KeyValuePair<string, string>
when to use FormUrlEncodedContent
Creating a new list
List<KeyValuePair<string, object>> keyValues = new List<KeyValuePair<string, object>>();
keyValues.Add(new KeyValuePair<string, object>("email", "asdasd"));
keyValues.Add(new KeyValuePair<string, object>("password", "1131"));
keyValues.Add(new KeyValuePair<string, object>("plan_id", 123));
keyValues.Add(new KeyValuePair<string, object>("other_field", null));
var content = new FormUrlEncodedContent(keyValues.Select(s =>
new KeyValuePair<string, string>(s.Key, s.Value != null ? s.ToString() : null)
));
Convert list
public static KeyValuePair<string, string> ConvertRules(KeyValuePair<string, object> kv)
{
return new KeyValuePair<string, string>(kv.Key, kv.Value != null ? kv.ToString() : null);
}
static Task Main(string[] args)
{
List<KeyValuePair<string, object>> keyValues = new List<KeyValuePair<string, object>>();
keyValues.Add(new KeyValuePair<string, object>("email", "asdasd"));
keyValues.Add(new KeyValuePair<string, object>("password", "1131"));
keyValues.Add(new KeyValuePair<string, object>("plan_id", 123));
keyValues.Add(new KeyValuePair<string, object>("other_field", null));
var content = new FormUrlEncodedContent(keyValues.ConvertAll(ConvertRules)));
));