我是AFNetworking的新手,我知道如何传递网址参数。但是我如何将标题传递到同一个调用中。
我也是AFHTTPSessionManager的子类
请参阅下面的代码:
- (void)getExpenses:(NSString *)page
success:(void (^) (NSArray *myExpenses))success
failure:(RequestFailureBlock)failure
{
NSString *resourceURL = [NSString stringWithFormat:@"%@/expenses/", APIBaseURLString];
NSDictionary *parameters = @{@"page":page, @"Authorization": APIAuthorization};
[self getExpenses:resourceURL parameters:parameters success:success failure:failure];
}
答案 0 :(得分:6)
michaels回答是正确的,使用
[self.requestSerializer setValue:@"Some-Value" forHTTPHeaderField:@"Header-Field"];
或
[self.requestSerializer setAuthorizationHeaderFieldWithUsername:@"" password:@""];
用于基本身份验证
答案 1 :(得分:0)
您在AFHTTPSessionManager的requestSerializer属性上设置标题值:
[self.requestSerializer setValue:@"Some-Value" forHTTPHeaderField:@"Header-Field"];
编辑:
看起来你正试图设置授权;也有一种方法:
[self.requestSerializer setAuthorizationHeaderFieldWithUsername:@"" password:@""];
// OR
[self.requestSerializer setAuthorizationHeaderFieldWithToken:@""];
如果您需要设置Content-Type
标题,请参阅this SO answer了解如何操作