Curl -F equivalente en C #
Estoy tratando de usar el objeto HTTPClient en C # para enviar una solicitud de publicación a una API. Este es el comando CURL:
curl -X POST https://zzz.zzz.zzz/yyy -F Key=abcd -F media=@"audio.aac"
Escribí el siguiente código:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Http;
using System.IO;
using System.Net.Http.Headers;
namespace Speech2Text
{
class Program
{
static void Main(string[] args)
{
curl().Wait();
}
static async Task curl()
{
var client = new HttpClient();
//Create List of KeyValuePairs
List<KeyValuePair<string, string>> bodyProperties = new List<KeyValuePair<string, string>>();
bodyProperties.Add(new KeyValuePair<string, string>("key", "abcd"));
bodyProperties.Add(new KeyValuePair<string, string>("media", "@audio.aac"));
var dataContent = new FormUrlEncodedContent(bodyProperties.ToArray());
HttpResponseMessage response = await client.PostAsync("https://zzz.zzz.zzz/yyy", dataContent);
HttpContent responseContent = response.Content;
using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
{
Console.WriteLine(await reader.ReadToEndAsync());
}
}
}
}
Pero sigo recibiendo esto:
{"code":400,"message":"Please use [media] for the media file field name in your POST request."}
¿Hay algún problema en la variable dataContect o es otra cosa?