I want to use AFHTTPRequestOperationManager
in my project. Each request should contain an authorization header. Otherwise server reports an error.
Well, I create an AFHTTPRequestOperationManager
:
- (void) setManager:(AFHTTPRequestOperationManager *)manager
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_manager = [AFHTTPRequestOperationManager manager];
_manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain", nil];
_manager.operationQueue.maxConcurrentOperationCount = 1;
[_manager.requestSerializer setValue:@"XsziXjva92jAO29jng0wpBmKFJ92s9q" forHTTPHeaderField:@"Authorization"];
});
}
And send a request with the help of the manager:
+ (void) requestBoards
{
// show me my manager headers
DLog(@"%@", [[[[RequestManager instance] manager] requestSerializer] HTTPRequestHeaders]);
[[[RequestManager instance] manager] GET:URL_BOARDS parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
DLog(@"good");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// show me request headers
DLog(@"%@", operation.request.allHTTPHeaderFields);
}];
}
Each DLog
shows:
[RequestManager requestBoards]_block_invoke_2 [Line 66] {
"Accept-Language" = "en;q=1";
Authorization = XsziXjva92jAO29jng0wpBmKFJ92s9q;
"User-Agent" = "SITE/1.0 (iPhone Simulator; iOS 8.1; Scale/2.00)";
}
And the server response is no good:
{"data": {}, "error_text": "Key None is unauthorized, sorry :/", "success": false, "error": "unauthorized_key"}
I decided to check my request with Wireshark and there is no Authorization header at all. What am I doing wrong?
Added:
Only Authorization header isn't send by AFHTTPRequestOperationManager
. I have changed header title to AuthorizationLOL and is was sent successfully