0
我有一個需要添加自定義標頭auth_token的項目。我不清楚如何添加到AFHTTPRequestOperation。我有:將自定義標頭添加到NSURLRequest或AFHTTPRequestOperation
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
// Configure Session Configuration
[sessionConfiguration setAllowsCellularAccess:YES];
[sessionConfiguration setHTTPAdditionalHeaders:@{ @"auth_token" : [self.credentialStore authToken]}];
// Create Session
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@/arc/v1/api/mi/images",MYHost()]];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
//[manager.requestSerializer setValue:[self.credentialStore authToken] forHTTPHeaderField:@"auth_token"];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
...
[[NSOperationQueue mainQueue] addOperation:op];
我該如何將auth_token添加爲自定義標題?
在其他地方,我們使用:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setValue:[self.credentialStore authToken] forHTTPHeaderField:@"auth_token"];
如果這是首選的方式,我可以在該樣式移植代碼。使用AFNetworking當
THX任何幫助
是的,我同意 - 說實話,這是一個被採納的項目,理想情況下只是讓它工作,而不是引入多個變化。有點驚訝,它是多麼神祕,它是添加到NSURLRequest – timpone 2014-10-03 23:36:46
我剛剛結束這樣做。 – timpone 2014-10-04 01:49:52