iosobjective-cafnetworking

How to send a post request to API with user information without getting blank response


I'm sending a NSMutalbeDictionary User with the correct information.

I have sending post using these two methods.

+ (void)loginUsers:(NSMutableDictionary*)user  {
    NSString *endpoint = @"api/users/sign_in";
    [self postEndpoint:endpoint params:user completionBlock:^(TSystemsResponse *response) {
        
        
    }];
}


    + (void)postEndpoint:(NSString *)endpoint params:(NSMutableDictionary *)params completionBlock:(void (^)(TSystemsResponse *response))completionBlock {
        [[TSystemsAPIClient sharedClient] postPath:[NSString stringWithFormat:@"/%@", endpoint] parameters:params success:^(AFHTTPRequestOperation *request, id responseObject) {
            TSystemsResponse *resp = [[TSystemsResponse alloc] initWithDictionary:responseObject];
            completionBlock(resp);
        } failure:^(AFHTTPRequestOperation *request, NSError *error) {
            NSLog(@"Request to /%@ FAILED: %@", endpoint, error);
            completionBlock(nil);
        }];
    }

I'm getting a response from the server that says the following

{
    "success": false,
    "message": "Missing user parameter"
}

So I'm thinking that I'm not sending the information through correctly. The API call works in Postman.


Solution

  • Double check the params variable actually has the key "user" and not uppercased:

    NSLog(@"%@", params);
    [self postEndpoint:endpoint params:params completionBlock:nil];
    

    If that is not the case you have to show us the innards of TSystemsAPIClient postPath:parameters:success: method.