Ios AF2.5如何设置forHTTPHeaderField的值
如何在AF2.5中执行以下操作。 我在旧版本中编写了以下代码:Ios AF2.5如何设置forHTTPHeaderField的值,ios,xcode,afnetworking,Ios,Xcode,Afnetworking,如何在AF2.5中执行以下操作。 我在旧版本中编写了以下代码: -(void)login{ NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: username.text,@"username",password.text,@"password",nil]; AFHTTPClient *httpClient= [[AFHTTPClient
-(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];
}
这就是我在AF2.5中所做的
-(void)login
{
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
username.text,@"email",password.text,@"password",nil];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setValue:some_value forHTTPHeaderField:@"some_field"];
[manager POST:@"some_url" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"JSON: %@", responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSLog(@"Error: %@", error);
}];
}
有很多关于从AF1迁移到AF2的文章和堆栈溢出页面。我建议你看看它们,因为它们回答了你的确切问题。你能给我提供这样的链接吗?因为我还没有找到它。