Я общаюсь с конечной точкой, созданной другой командой в ядре asp.net, которая принимает ([FromBody] кандидат-кандидат)
Объект кандидата выглядит следующим образом:
< бр />
Код: Выделить всё
public class Applicant
{
public string FirstName{get; set;}
public string LastName{get; set;}
public List Reports{get; set;}
}
Код: Выделить всё
public class Reports
{
public string ReportName {get;set;}
public byte[] ReportFile {get;set;}
}
and a second time where I send an applicant with two report files. This is what I have so far:
Код: Выделить всё
byte[] report1 = new UTF8Encoding(true).GetBytes("This is a test report1");
byte[] report2 = new UTF8Encoding(true).GetBytes("This is a test report2");
byte[] report3 = new UTF8Encoding(true).GetBytes("This is a test report3");
var reportOjbect = new
{
FirstName = "John",
LastName = "Doe",
Reports = new []
{
new {
ReportName = "6 week Report",
ReportFile = report1
}
}
};
var baseUrl = "localhost:1111";
var endpoint = "/api/validate-reports";
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(baseUrl);
var content = new MultipartFormDataContent();
content.Add(new StringContent(reportOjbect.FirstName), "FirstName");
content.Add(new StringContent(reportOjbect.LastName), "LastName");
//How to add list of reports here that contain both the report name and the report file
var request = new HttpRequestMessage(HttpMethod.Post, $"{baseUrl}{endpoint}")
{ Content = content};
var response = await httpClient.SendAsync(request);
if (!response.IsSuccessStatusCode)
{
throw new Exception($"Failed to send email: {response.StatusCode}");
}
return Results.Ok("Reports were processed");
Источник: https://stackoverflow.com/questions/781 ... in-c-sharp
Мобильная версия