How to make a request correctly?

There is code in PHP, translate it in C#:

$fields = array(
 'Page' => $page,
 'Sides' => array(
),
);

$fields_string = http_build_query($fields);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);


That is, send a post request:

var values = new List<KeyValuePair<string, string>>
{
 new KeyValuePair<string, string>("Page", Page)
};

//how can I add an array?

var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync(ur, content);


In other words, how to put string in array, then it is chewed FormUrlEncodedConten?
April 19th 20 at 12:31
2 answers
April 19th 20 at 12:33
Solution
Try
var values = new List<KeyValuePair<string, string>>
{
 new KeyValuePair<string, string>("Page", Page)
 new KeyValuePair<string, string>("Sides[0]", side1),
 new KeyValuePair<string, string>("Sides[1]", side2),
....
 };

Or
var values = new List<KeyValuePair<string, string>>
{
 new KeyValuePair<string, string>("Page", Page)
};
for(var i = 0; i < sides.Length;i++)
 values.Add( new KeyValuePair<string, string>("Sides["+i+"]", sides[i]));

PS In a pinch you can write your method http_build_query which will take some sort of Dictinary < string ,object >, and the clever shaping of the array. Although you may already have some sort of similar method you need to read docks
April 19th 20 at 12:35
Decided by a simple manual conversion, if anyone is interested:

string json = "{'Page':1,'Count':25,'Sides':['"+ Sides + "']}";

Find more questions by tags C#