I want to create a Webservice. This webservice should call an other Endpoint from different services. That means, the Webservice should work like a Proxy.
I realize all GET Methods and one POST Method. But the last POST Method don't work. It is different to the first method.
In the first Method i get a file (datatype IFormFile) in the Body of the Post-Request as form-data. The response is the Status OK. That works.
In the second Method i get also such a file and some additional information (datatype string and int) in the Body of the Post-Request as form-data. But that doesn't work.
I have no error in the code itself. I have tried it out with Postman, load all the data as form-data in the body. I send the data and see in the logs the Post, but i need the response, which came back and there is no data. How should i do this.
That, what i posted, is the code right know. There you got a statuscode. But i don't need a statuscode. I need a responseBody. I have tried it with HttpContent and HttpResponseMessage. Both are empty.
What i do wrong?
What I have tried:
[HttpPost("Test")]
public StatusCodeResult trace(IFormFile file)
{
try
{
if (file != null && file.Length > 0)
{
using (var client = new HttpClient())
{
try
{
client.BaseAddress = new Uri("https://localhost:40111");
byte[] data;
using (var br = new BinaryReader(file.OpenReadStream()))
data = br.ReadBytes((int)file.OpenReadStream().Length);
ByteArrayContent bytes = new ByteArrayContent(data);
MultipartFormDataContent multiContent = new MultipartFormDataContent();
multiContent.Add(bytes, "image", file.FileName);
multiContent.Add(new StringContent("132"), "itemId");
var result = client.PostAsync("/test", multiContent).Result;
HttpContent response = result.Content;
return StatusCode((int)result.StatusCode);
}
catch (Exception)
{
return StatusCode(500);
}
}
}
return StatusCode(400);
}
catch (Exception)
{
return StatusCode(500);
}
}