ladessa-ios
ladessa-ios

Reputation: 283

Code=-1011 "Request failed: unauthorized (401)" AFNetwoking

I'm trying to make a GET request setting a header called

X-User-Authorization but I'm getting the following error:

Code=-1011 "Request failed: unauthorized (401)" AFNetwoking

 -(void) listarGruposDeDistancia
    {
        NSMutableArray *listaDistancias = [[NSMutableArray alloc]init];
        AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        manager.requestSerializer = [AFHTTPRequestSerializer serializer];
        manager.requestSerializer.allowsCellularAccess = YES;
        [manager.requestSerializer setValue:@"valueHere" forHTTPHeaderField:@"X-User-Authorization"];

       AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
        policy.allowInvalidCertificates = YES;
        manager.securityPolicy = policy;

        NSString *url = @"https://url:3000/api/v0.1/groups/";

        [manager GET:url
          parameters:nil
             success:^(AFHTTPRequestOperation *operation, id responseObject) {

                NSLog(@“success”);
                 }
                 [self concluirListaDistancias:listaDistancias];

             } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                 NSLog(@"Error: %@", error);
             }];
    }

Upvotes: 0

Views: 3821

Answers (1)

brandonscript
brandonscript

Reputation: 72825

You're definitely getting a 401 back from the server - meaning you haven't constructed an appropriate HTTP request with authentication according to what the server requires. Review the documentation of the (service provider or in your case what appears to be a local packaged product), then use tools like and to construct an appropriate HTTP request. When you're confident the raw requests are working as expected, use something like requestb.in to test your AFNetworking request.

For what it's worth, X-User-Authorization isn't a pre-configured authorization header (The X- prefix implies it's a custom header attribute). Maybe you're looking for something more like Authorization: Bearer <token>?

Upvotes: 1

Related Questions