Curl -F-Äquivalent in C #

Ich versuche, ein HTTPClient-Objekt in C # zu verwenden, um eine Post-Anfrage an eine API zu senden. Dies ist der CURL-Befehl:

curl -X POST https://zzz.zzz.zzz/yyy -F Key=abcd -F media=@"audio.aac"

Ich habe den folgenden Code geschrieben:

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());
        }
    }
  }
}

Aber ich bekomme immer das:

{"code":400,"message":"Please use [media] for the media file field name in your POST request."}

Ist die dataContect-Variable fehlerhaft oder ist es etwas anderes?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage