0
votes

Please help to advise for my issue below.

I try to create an enrollment using sample code from here

private async Task<HttpResponseMessage> MakeRequest()
    {
        string path = @"<path_to_wav_file>";
        var client = new HttpClient();
        var queryString = HttpUtility.ParseQueryString(string.Empty);

        // Request headers
        client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "<my_key>");

        // Request parameters
        queryString["shortAudio"] = "true";
        queryString["identificationProfileId"] = "<my_profile_id>";
        var uri = "https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles/<my_profile_id>/enroll?" + queryString;

        HttpResponseMessage response;

        // Request body
        byte[] byteData = File.ReadAllBytes(path);

        using (var content = new ByteArrayContent(byteData))
        {
            content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            response = await client.PostAsync(uri, content);
        }

        return response;
    }

and got the response

{StatusCode: 202, ReasonPhrase: 'Accepted', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Pragma: no-cache
Operation-Location: https://westus.api.cognitive.microsoft.com/spid/v1.0/operations/af54c843-8df9-4511-8d65-4825ebec024d apim-request-id: 37567cff-d259-4a1d-82fc-9fc884edcfe3
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload x-content-type-options: nosniff Cache-Control: no-cache
Date: Tue, 08 Jan 2019 07:12:05 GMT X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET Content-Length: 0 Expires: -1 }}

said that

{"error":{"code":"Unspecified","message":"Access denied due to invalid subscription key. Make sure you are subscribed to an API you are trying to call and provide the right key."}}

The error message is strange because I used the same Subscription Key that created profile successfully.

1

1 Answers

1
votes

I think you should use ("Ocp-Apim-Subscription-Key", "") when make request to https://api.projectoxford.ai/spid/v1.0/operations/af54c843-8df9-4511-8d65-4825ebec024d