I'm receiving the following error while accessing the Microsoft Cognitive API:
I'm 100% sure that my subscription key is valid because I have tested it in DHC as well as the online tool of Project Oxford.
I'm using sample code provided by Microsoft. Here it is...
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString("safeee");
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{bce8988422e94fd3ac64xxxxxxxxxxxx}");
var uri = "https://api.projectoxford.ai/face/v1.0/persongroups/{personGroupId}?" + queryString;
HttpResponseMessage response;
byte[] byteData = Encoding.UTF8.GetBytes("{body}");
using (var content = new ByteArrayContent(byteData))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
response = await client.PutAsync(uri, content);
MessageBox.Show(response.ToString());
}
For any code snippet in the Microsoft Cognitive Services site, including the page to which I believe you're referring, you need to substitute all curly-braced strings with appropriate values. In your case, you need to:
"safeee"
from the queryString
. There are no query parameters for this particular endpoint. Ocp-Apim-Subscription-Key
value (sounds like you tried that.) personGroupId
value. Per the documentation on the aforementioned page, "valid characters include numbers, English letters in lower case, '-' and '_'. The maximum length of the personGroupId is 64." body
. In your case you might simply use "{\\"name\\":\\"safeee\\"}"
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.