Метод в первый проект:
Код: Выделить всё
public async Task GetTemplateAsync()
{
try
{
string uri = $"{_uri}GetTemplate";
var result = await _httpClient.GetAsync(uri);
if (!result.IsSuccessStatusCode)
{
throw new Exception(await result.Content.ReadAsStringAsync());
}
byte[] template = await result.Content.ReadAsByteArrayAsync();
return template;
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
Код: Выделить всё
[HttpGet("/GetTemplate")]
[Produces("application/octet-stream")]
public HttpResponseMessage GetTemplate()
{
try
{
byte[] boletoTemplate = _templateService.GetTemplate();
HttpResponseMessage response = new(HttpStatusCode.OK)
{
Content = new ByteArrayContent(boletoTemplate)
};
return response;
}
catch (NotFoundException ex)
{
return new HttpResponseMessage(HttpStatusCode.NotFound)
{
Content = new StringContent(ex.Message)
};
}
catch (Exception ex)
{
return new HttpResponseMessage(HttpStatusCode.BadRequest)
{
Content = new StringContent(ex.Message)
};
}
}
Это происходит когда я добавляю аннотацию
Код: Выделить всё
[Produces("application/octet-stream")]
p>
Редактировать =================================== =================
Эта проблема существует в проекте .Net 8.0. Когда я использую почтальона для отправки запроса в ту же конечную точку, он возвращает 406 Not Acceptable
Подробнее здесь: https://stackoverflow.com/questions/785 ... tet-stream