0
我正在尝试使用AFHTTPClient进行其他API调用。我试图通过将注册的认证密钥传递给api来完成api请求。当我运行该应用程序时,出现403错误。我是使用AFNetworking的新手,我非常感谢这方面的帮助。使用AFHttpClient请求使用验证密钥的API
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];
这是我的代码完全错误。这真的很有帮助。非常感谢你挽救我的头痛:) – Harish 2013-03-19 10:26:21