I have the following controller method:
[HttpPost]
[Route("SomeRoute")]
public byte[] MyMethod([FromBody] string ID)
{
byte[] mybytearray = db.getmybytearray(ID);//working fine,returning proper result.
return mybytearray;
}
Now in the calling method(thats also another WebApi method!) I have written like this:
private HttpClient client = new HttpClient ();
private HttpResponseMessage response = new HttpResponseMessage ();
byte[] mybytearray = null;
response = client.GetAsync(string.Format("api/ABC/MyMethod/{0}", ID)).Result;
if (response.IsSuccessStatusCode)
{
mybytearray = response.Content.ReadAsByteArrayAsync().Result;//Here is the problem
}
Now, the problem is the byte array MyMethod
is sending is of 528 bytes, but here after making ReadAsByteArrayAsync
, the size becomes larger(706 bytes) and the values are also goofed up.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…