Im trying to send a http post request from Action1 to Action2 and instead of sending the payload as string Im sending it as stream for performance. Im getting the error.
Unsupported Media Type
[ApiController]
[Route("api/v1/test")]
[ExcludeFromCodeCoverage]
public class TestController : Controller
{
private readonly IHttpCommunicator _httpCommunicator;
private readonly IObjectSerializer _objectSerializer;
public TestController(IHttpCommunicator httpCommunicator, IObjectSerializer objectSerializer)
{
_httpCommunicator = httpCommunicator;
_objectSerializer = objectSerializer;
}
[HttpPost]
[Route("Action1")]
public async Task<IActionResult> Action1()
{
var payload = new DocumentEntity
{
Id = Guid.NewGuid().ToString(),
Name = "My Document",
Content = System.IO.File.ReadAllBytes(@"2705 v1 1.docx")
};
var stream = _objectSerializer.SerializeToStream(payload);
var httpCommunicationRequest = new HttpCommunicationRequest
{
IsPlatformService = true,
Url = "https://localhost:3333/api/v1/Action2",
Method = HttpMethod.Post,
Data = stream,
};
var httpCommunicationResponse = await _httpCommunicator.Send(httpCommunicationRequest);
return new JsonResult(httpCommunicationResponse);
}
[HttpPost]
[Route("Action2")]
public IActionResult Action2(DocumentEntity documentEntity)
{
return new JsonResult(new { Success = true });
}
}