I am writing a C# client for a 3rd party API (I'm using the RestSharp nuget package). Their documentation contains PHP examples which I must translate to C#. Most of their samples are simple enough and I have been able to convert them to C# but I am struggling with one of them because it accepts an array of arrays. Here's the sample from their documentation:
$params = array (
'user_key' => 'X',
'client_id'=> 'X,
'label' => array(
array(
'language' => 'en_US',
'name' => 'English label',
),
array(
'language' => 'fr_CA',
'name' => 'French label',
),
),
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.3rdparty.com/xxx/yyy');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apikey: YOURAPIKEY'));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
Here's what I have so far:
var labels = new Dictionary<string, string>()
{
{ "en_US", "English Label" },
{ "fr_CA", "French Label" }
};
var request = new RestRequest("/xxx/yyy", Method.POST) { RequestFormat = DataFormat.Json };
request.AddHeader("apikey", myApiKey);
request.AddParameter("user_key", myUserKey);
request.AddParameter("client_id", myClientId);
request.AddParameter("label", ???);
var client = new RestSharp.RestClient("https://api.3rdparty.com")
{
Timeout = timeout,
UserAgent = "My .NET REST Client"
};
var response = client.Execute(request);
Does anybody know how to convert the "labels" dictionary into a format that would be equivalent to PHP's http_build_query?