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

前端 未结 7 1160
故里飘歌
故里飘歌 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:34

    This is my approach its worked for me

    WEP API Method

                [HttpGet]
                [Route("pdfReport")]
                public byte[] ReportMRWiseCurrentStatus()
                {
        
                    byte[] resultsarray = _materialRequestReportService.ReportMRWiseCurrentStatus();
                    return resultsarray;
                }
    

    The Client

    using (var client = new HttpClient())
                {
                    var response = client.GetAsync(webApiUrl);
                    if (response.Result.IsSuccessStatusCode)
                    {
    
                        var result = response.Result.Content.ReadAsStringAsync().Result.Replace("\"", string.Empty);
    
                        var bytearray=Convert.FromBase64String(result);
                        System.IO.File.WriteAllBytes(@"C:\DB\newpdfAmila.pdf", bytearray);
                    }
    
                 }
    
    0 讨论(0)
提交回复
热议问题