3
When I run the code below, it gives error on this line:
Literal1.Text= ObterEmocoes(imageFilePath);
Is giving this error message:
An object reference is required for the non-static "Program.Get (string)" field, method, or 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;
}
}
you... translated the error message?
– Daniel
The message is clear, you need to create an instance of the class. The way you are calling the method should be static
– Ricardo Pontual