Basic authentication using AFNetworking

0

How can I do basic HTTP authentication using AFNetworking in Objective - C?

    
asked by anonymous 25.07.2015 / 05:25

1 answer

0

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);
}];
    
26.07.2015 / 13:52