我正在尝试使用 AFHTTPClient 进行休息 api 调用。我正在尝试通过将注册时获得的身份验证密钥传递给 api 来发出 api 请求。当我运行该应用程序时,我收到 403 错误。我是使用 AFNetworking 的新手,我非常感谢任何帮助。
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://somewebsite.com/"]];
[httpClient setDefaultHeader:@"Authorization: Client-ID" value:@"xxxxxxxx"];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET"
path:@"https://api.somewebsite.com/api/category/subcategory/fun/"
parameters:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// Print the response body in text
NSLog(@"Response: %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];