Waz*_*zie 2 azure microsoft-cognitive
我正在使用Microsoft Azure认知服务进行人脸识别项目。不太确定为什么我不能更正自己的JSON格式错误的语法,我以为6个月前就确定了这一点。我想创建一个组名,所以我调用“ Person Group API”,每次我遵循MS示例时,我的代码都会出错,但是在API测试控制台中,这没有问题,这是我从MS网站借来的代码示例:
{ "error": { "code": "ResourceNotFound", "message": "The requested resource was not found." } }
Run Code Online (Sandbox Code Playgroud)
以及在控制台模式下运行的代码:
static async void CreateGroup()
{
string key1 = "YourKey";
// azure the one should work
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add
("Ocp-Apim-Subscription-Key", key1);
var uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/
persongroups/{personGroupId}?" + queryString;
HttpResponseMessage response;
// Request body
string groupname = "myfriends";
string body = "{\"name\":\"" + groupname + ","+ "\"}";
// Request body
using (var content = new StringContent
(body, Encoding.UTF8, "application/json"))
{
await client.PostAsync(uri, content)
.ContinueWith(async responseTask =>
{
var responseBody = await responseTask.Result
.Content.ReadAsStringAsync();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Response: {0}", responseBody);
Console.WriteLine("");
Console.WriteLine("Group Created.... ");
Console.WriteLine("Hit ENTER to exit...");
Console.ReadKey();
});
response = await client.PutAsync(uri, content);
Console.WriteLine("what is this {0}", response.ToString());
Console.ReadKey();
}// end of using statement
}// end of CreateGroup
#endregion
Run Code Online (Sandbox Code Playgroud)
我想在这里,但我认为它的JSON再次格式错误,而我只是不知道这次我又在做什么错。根据站点,我需要发送给ms的字段名称'name' : 'userData'是可选的。
小智 5
面对类似的问题,在uri中添加“ / detect”后,问题已解决。见下面
var uri = "https://westus.api.cognitive.microsoft.com/face/v1.0/detect
Run Code Online (Sandbox Code Playgroud)
另外,请确保订阅密钥有效。