How to Get byte array properly from an Web Api Method in C#?

前端 未结 7 1196
故里飘歌
故里飘歌 2020-11-30 01:49

I have the following controller method:

[HttpPost]
[Route("SomeRoute")]
public byte[] MyMethod([FromBody] string ID)
{
  byte[] mybytearray = db.get         


        
7条回答
  •  囚心锁ツ
    2020-11-30 02:12

    Instead of this

    mybytearray = response.Content.ReadAsByteArrayAsync().Result;//Here is the problem
    

    Use this

    string result=null;
    result = response.Content.ReadAsStringAsync().Result.Replace("\"", string.Empty);
     mybytearray=Convert.FromBase64String(result);
    

    response was returning the byte array as base64encoded.

提交回复
热议问题