I'm having some issues with calling an API. I need to send post data containing 2 things: an ID and an array of int. I have tried a lot of things, all resulting in errors or simply not sending data in the right way. All answers I found, do not handle the fact that I want to send 2 different data types.
On the other side I have:
Call<DefaultResponseList> someMethod(@Field("parm1") String parm1, @Field("parm2[]") ArrayList<Integer> parm2);
I tried:
List<int> ints1 = new List<int>();
ids.Add(1);
ids.Add(2);
ids.Add(3);
var values = new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("parm1", "lkdjfowejfd123"),
new KeyValuePair<string, object>("parm2", ints1)
};
var httpClient = new HttpClient(new HttpClientHandler());
HttpResponseMessage response = await httpClient.PostAsync(someUrl, new FormUrlEncodedContent(values));
response.EnsureSuccessStatusCode();
string data = await response.Content.ReadAsStringAsync();
someUrl's environment and then arrange your values according to this information. Ex if target environment is a Apache/PHP server your keys should be like param2[], for classic ASP.NET envrionment values should have same key name with occurence, and if its ASP.NET MVC your key should contains indices like param2[0],param2[1] etc.