Forum Discussion

Afshan Anwar ali's avatar
Afshan Anwar ali
Copper Contributor
Jul 24, 2018

Face API - Face detect

While using Face detect service of Face API V1.0 I encounter no errors but no result also. I am working on c#. Any help is appreciated. Thanks in advance.

 

Code is as follows:

using System;
using System.Net.Http.Headers;
using System.Text;
using System.Net.Http;
using System.Web;

namespace CSHttpClientSample
{
static class Program
{
static void Main()
{
MakeRequest();
Console.WriteLine("Hit ENTER to exit...");
Console.ReadLine();
}

static async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);

// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "9b0bd0ce75d040769834af2339b93e1d");

// Request parameters
queryString["returnFaceId"] = "true";
queryString["returnFaceLandmarks"] = "false";
queryString["returnFaceAttributes"] = "Age";
//var uri = "https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect" + queryString;
var uri = "https://eastasia.api.cognitive.microsoft.com/face/v1.0/detect" + queryString;

HttpResponseMessage response;

// Request body
byte[] byteData = Encoding.UTF8.GetBytes("https://i.kinja-img.com/gawker-media/image/upload/s--0MPvwvU0--/c_scale,f_auto,fl_progressive,q_80,w_800/miszpljlzalcgcejpeai.png");

using (var content = new ByteArrayContent(byteData))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

response = await client.PostAsync(uri, content);
}

}
}
}

No RepliesBe the first to reply

Resources