C# 如何使用post请求调用web api以字节数组形式发送文件?

C# 如何使用post请求调用web api以字节数组形式发送文件?,c#,arrays,pdf,post,webapi,C#,Arrays,Pdf,Post,Webapi,我试图调用一个以字节数组为参数的web api [HttpPost] [Route("getfields")] public List<string> GetFields(byte[] bytearray) { HelperClass pdf = new HelperClass (); List<string> fields = pdf.GetFormFields(bytearray); return fields;

我试图调用一个以字节数组为参数的web api

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

我得到错误500,但它没有进入api控制器。我还尝试了application/bson,它给出了415错误不支持的媒体类型。谢谢

尝试使用完整的请求URI?例如“是的,我在我身边使用完整的基址。@Mollycurryness可以试试这个解决方案吗?已经在使用相同的:ByteArrayContent byteContent=新的ByteArrayContent(数据);HttpResponseMessage-Response=等待客户端.postSync(uri,字节内容)@使用完整请求URI的MouldyCurrenyStry?例如“是的,我在我身边使用完整的基址。@Mollycurryness可以试试这个解决方案吗?已经在使用相同的:ByteArrayContent byteContent=新的ByteArrayContent(数据);HttpResponseMessage-Response=等待客户端.postSync(uri,字节内容)@霉变货币
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();