How to send multiple parameterts to PHP server in HTTP post

For the network operation these is better supporting API like AFNetworking available witch work async and way better to handle

Tutorials for AFNetworking

Get from here

NSArray *keys = @[@"UserID", ];
NSArray *objects = @[@(userId)];

NSDictionary *parameter = [NSDictionary dictionaryWithObjects:objects forKeys:keys];

AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:
                            [NSURL URLWithString:BaseURLString]];
[httpClient setParameterEncoding:AFJSONParameterEncoding];
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];

NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST"
                                                        path:@"services/UserService.svc/GetUserInfo"
                                                  parameters:parameter];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

    NSError* error = nil;
    id jsonObject = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:&error];
    if ([jsonObject isKindOfClass:[NSDictionary class]]) {
        // do what ever
    }
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

}];

Leave a Comment