Senden von StreamContent und StringContent an die APIC#

Ein Treffpunkt für C#-Programmierer
Guest
 Senden von StreamContent und StringContent an die API

Post by Guest »

Versuche derzeit, 2 Bilder und einen String an eine API zu senden.
ApiCall:

Code: Select all

var data = new
{
mode = info
};

pathData = JsonConvert.SerializeObject(data.ToString());

var content = new MultipartFormDataContent
{
{ new StreamContent(frontStream), "front", front.FullName },
{ new StreamContent(backStream), "back", back.FullName },
{ new StringContent(pathData, Encoding.UTF8, "application/json") }
};

using var client = new HttpClient();
var response = await client.PostAsync($"https://localhost:987987987/Upload", content);
Ich habe es mit [FromBody] versucht und erhalte immer noch die Antwort „Nicht unterstützter Medientyp“.
Api:

Code: Select all

[HttpPost]
public async Task Post(IFormFile front, IFormFile back, [FromBody] string mode)
{
return Ok();
}
Jede Hilfe wird sehr geschätzt, vielen Dank!

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post