Cognitive Face API返回Web应用程序没有结果

问题描述 投票:0回答:1

我正在使用Microsoft Cognitive Face API实现人脸检测以验证此人并登录该应用程序。

为此,我正在创建一个PersonGroup并添加Person,然后添加Person of Face。火车人组等。

我想在MVC Web应用程序中实现它。我在MVC Web应用程序中编写了相同的代码。但API没有返回任何内容,只是挂在Http请求调用上。

那么我们是否需要为Web应用程序获取一些不同的API密钥,或者我们是否需要在Web.Config文件中进行任何更改才能成功调用?

我在控制台应用程序和WPF应用程序中尝试了相同的代码。一切都很好。

public class HttpClientHelper
    {
        HttpClient httpClient = new HttpClient();

        private const string subscriptionKey = "XXXXXXXXXXXXXXXXXXXXXXXXXX";

        private const string faceEndpoint = "https://southeastasia.api.cognitive.microsoft.com/face/v1.0/";

        public HttpClientHelper()
        {
            httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
            httpClient.BaseAddress = new Uri(faceEndpoint);
        }

        public async Task<T> GetAsync<T>(string url)
        {
            var response = await httpClient.GetAsync(url);
            string contentString = await response.Content.ReadAsStringAsync();
            return JsonConvert.DeserializeObject<T>(contentString);
        }
    }


public static async Task CreatePersonGroup(UserGroup userGroup)
        {
            bool isGroupExists = false;
            PersonGroup personGroup;

            try
            {
                HttpClientHelper httpClientHelper = new HttpClientHelper();
                var response = httpClientHelper.GetAsync<PersonGroup>(string.Format("persongroups/{0}", userGroup.UserGroupId)).Result;

               isGroupExists = true;
            }
            catch (APIErrorException ex)
            {
                if (ex.Body.Error.Code == "PersonGroupNotFound")
                    isGroupExists = false;
            }

            if (isGroupExists == false)
            {
                await faceClient.PersonGroup.CreateAsync(userGroup.UserGroupId, userGroup.Name);
            }
        }

我希望相同的代码也必须在Web应用程序中正常工作。因为它没有很大的逻辑。只是一个简单的API调用。

microsoft-cognitive azure-cognitive-services face-api
1个回答
0
投票
private const string faceEndpoint = 
"https://southeastasia.api.cognitive.microsoft.com/";

希望它应该有效

© www.soinside.com 2019 - 2024. All rights reserved.