1

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

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

我将 api 称为如下:

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();

我收到错误 500,它没有进入 api 控制器。我也尝试过应用程序/bson,它给出了 415 错误不支持的媒体类型。谢谢

4

0 回答 0