When I execute the code below, it gives error in this line:
Literal1.Text= ObterEmocoes(imageFilePath);
You are giving this error message:
An object reference is required for the non-static field, method, or "Program.ObterEmocoes (string)" property
Code:
protected void Button1_Click(object sender, EventArgs e)
{
string imageFilePath = @"C:\Users\madureira\Downloads\JRMJ.jpg";
Literal1.Text= ObterEmocoes(imageFilePath);
}
public async Task<string> ObterEmocoes(string imagemBase64)
{
HttpResponseMessage respostaHttp;
string json;
byte[] bytesImagem = Convert.FromBase64String(imagemBase64);
string url = "https://brazilsouth.api.cognitive.microsoft.com/face/v1.0/detect";
string queryString = "returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes=age,emotion";
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "2b4d806c1cf5467bb8772f86c3fc0a2e");
using (var conteudoEmBytes = new ByteArrayContent(bytesImagem))
{
conteudoEmBytes.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
respostaHttp = await httpClient.PostAsync($"{url}?{queryString}", conteudoEmBytes);
json = await respostaHttp.Content.ReadAsStringAsync();
}
return json;
}
}