Senden von StreamContent und StringContent an die API

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Senden von StreamContent und StringContent an die API

by Guest » 31 Dec 2024, 14:19

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

Top