How can I do basic HTTP authentication using AFNetworking in Objective - C?
How can I do basic HTTP authentication using AFNetworking in Objective - C?
As well as other publications found here, the request is very similar. You will only need to add% of the authentication data using the requestSerializer
method.
In general, it looks something like this:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
[manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"usuario" password:@"senha"];
[manager GET:@"http://..." parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *response = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"%@", response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];