Error with calling Speaker Identification API. When i try to return a profile Id i get a Error: Error Domain=NSURLErrorDomain Code=-1012 "(null)"
The following error message is what i get when i try to return a profile Id for enrolment. I have already tried to see if it is an authentication error by using the API console, everything seems to be returning fine over there. I have provided my implementation/sample code below. Currently I am using the objective c code from the link below as a bridge header for my swift app:
This is the error message i receive when i try to return the Profile Id for Enrolment:
"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles?entities=true 2021-03-23 14:56:16.205386-0400 Reka[50677:760200] Error: Error Domain=NSURLErrorDomain Code=-1012 "(null)" UserInfo={NSErrorFailingURLStringKey=https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles?entities=true, NSUnderlyingError=0x600002755290 {Error Domain=kCFErrorDomainCFNetwork Code=-1012 "(null)" UserInfo={_kCFURLErrorAuthFailedResponseKey=<NSHTTPURLResponse: 0x600002a746a0> { URL: https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles?entities=true } { Status Code: 401, Headers { "Content-Length" = ( 225 ); "Content-Type" = ( "application/json" ); Date = ( "Tue, 23 Mar 2021 18:56:15 GMT" ); "Strict-Transport-Security" = ( "max-age=31536000; includeSubDomains; preload" ); "Www-Authenticate" = ( "AzureApiManagementKey realm=\"https://westus.api.cognitive.microsoft.com/spid/v1.0",name="Ocp-Apim-Subscription-Key",type="header""; ); "apim-request-id" = ( "5ab215e6-1efe-4f92-9468-3dc14a79567e" ); "x-content-type-options" = ( nosniff ); } }}}, NSErrorFailingURLKey=https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles?entities=true}";
Implementation of my code
@implementation PersonIdObject
(int) personIdMethod {
NSLog(@"SomeMethod Ran");
@autoreleasepool {
NSString* path = @"https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles";
NSArray* array = @[
// Request parameters
@"entities=true",
];
NSString* string = [array componentsJoinedByString:@"&"];
path = [path stringByAppendingFormat:@"?%@", string];
NSLog(@"%@", path);
NSMutableURLRequest* _request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:path]];
[_request setHTTPMethod:@"POST"];
// Request headers
[_request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[_request setValue:@"{subscription key}" forHTTPHeaderField:@"sub_key"];
// Request body
[_request setHTTPBody:[@"{body}" dataUsingEncoding:NSUTF8StringEncoding]];
NSURLResponse *response = nil;
NSError *error = nil;
NSData* _connectionData = [NSURLConnection sendSynchronousRequest:_request returningResponse:&response error:&error];
if (nil != error)
{
NSLog(@"Error: %@", error);
}
else
{
NSError* error = nil;
NSMutableDictionary* json = nil;
NSString* dataString = [[NSString alloc] initWithData:_connectionData encoding:NSUTF8StringEncoding];
NSLog(@"%@", dataString);
if (nil != _connectionData)
{
json = [NSJSONSerialization JSONObjectWithData:_connectionData options:NSJSONReadingMutableContainers error:&error];
}
if (error || !json)
{
NSLog(@"Could not parse loaded json with error:%@", error);
}
NSLog(@"%@", json);
_connectionData = nil;
}
//[pool drain];
return 0;
}
}