【发布时间】:2014-11-29 21:43:03
【问题描述】:
如何在 AFNetworking "2.5" 中执行以下操作。 我在较旧的 AFNetworking 版本中编写了这段代码:
-(void)login{
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
username.text,@"username",password.text,@"password",nil];
AFHTTPClient *httpClient= [[AFHTTPClient alloc]initWithBaseURL:[NSURL URLWithString:[NSString stringWithFormat:@"some_url"]]];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient setDefaultHeader:@"Accept" value:@"application/json"];
[httpClient setAuthorizationHeaderWithToken:@"Token"];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"some_path" parameters:params];
[request addValue:@"some_value" forHTTPHeaderField:@"some_field"];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"Response- %@", responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error- %@",error);
}];
[operation start];
}
【问题讨论】:
-
有很多关于从 AFNetworking 1 迁移到 2 的文章和 Stack Overflow 页面。我建议您看看它们,因为它们回答了您的确切问题。
-
你能给我这样的链接吗?因为我还没有找到。
标签: ios xcode afnetworking