1

I'm trying to call a web api that takes byte array as parameter

[HttpPost]
[Route("getfields")]
public List<string> GetFields(byte[] bytearray)
    {
        HelperClass pdf = new HelperClass ();
        List<string> fields = pdf.GetFormFields(bytearray);
        return fields;
    }

And i call the api as below:

HttpClient _httpClient = new HttpClient();
byte[] bytes = System.IO.File.ReadAllBytes(TemplatePath);// pdf path
var byteContent = new ByteArrayContent(bytes);
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
HttpResponseMessage response = await _httpClient.PostAsync("api/Controller/getfields", byteContent);
response.EnsureSuccessStatusCode();

I get error 500 and it doesn't go in the api controller. I have tried application/bson also that gives 415 error Unsupported Media Type. Thanks

0 Answers0