分析图像订阅密钥

时间:2017-06-28 03:42:47

标签: ios image azure subscription http-status-code-401

我对miscrsoft的描述是中国地区。我已经尝试了两个密钥(https://azure.microsoft.com/zh-cn/try/cognitive-services/my-apis/),but似乎不起作用。它返回“由于订阅密钥无效而拒绝访问。请确保为有效订阅提供有效密钥。”。我该怎么办? / p>

{

NSData *imageData = UIImageJPEGRepresentation(self.testImageView.image, 1.0);

NSArray *visualFeatures = @[@"Categories", @"Tags", @"Description", @"Faces", @"ImageType", @"Color", @"Adult"];

NSString *apiStr = @"https://api.projectoxford.ai/vision/v1.0/analyze";

NSString *urlStr = [NSString stringWithFormat:@"%@?visualFeatures=%@", apiStr, [visualFeatures componentsJoinedByString:@","]];

NSURL *url = [NSURL URLWithString:urlStr];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

// 设置请求方式
request.HTTPMethod = @"POST";

// 设置 header
[request setValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"];

[request setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];



[request setValue:@"a730bc89097b4ed292f70daee254adee" forHTTPHeaderField:@"Ocp-Apim-Subscription-Key"];
// 设置请求体
[request setHTTPBody:imageData];
NSLog(@"request = %@", request.URL.absoluteString);

NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data,NSURLResponse * _Nullable response, NSError * _Nullable error) {
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
    NSLog(@"请求返回值 =  %@",dict);
}];


[dataTask resume];

}

0 个答案:

没有答案