Basic authentication using Afnetworking

Asked

Viewed 46 times

0

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

1 answer

0


As well as other publications found here, the request is very similar. You will only need to add in requestSerializer authentication data using the method setAuthorizationHeaderFieldWithUsername.

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);
}];
  • Obrigado Paulo.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.