Hi I'm new with AFNetworking 2.0 and I need to connect in my php file using AFHTTPRequestOperationManager but if I get the response it's only returning null.
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.securityPolicy.allowInvalidCertificates = YES;
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFImageResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setObject:contactName forKey:kContactNameKey];
[parameters setObject:mailTo forKey:kMailToKey];
[parameters setObject:mailCc forKey:kMailCcKey];
[parameters setObject:category forKey:kCategoryKey];
[manager POST:@"http://www.sample.com/sample/sample.php" parameters:parameters
success:^(AFHTTPRequestOperation *operation,id responseObject){
NSLog(@"Success %@",responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"%@",error);
}];
btw here's a sample line in my php file
$EmailTo=mosGetParam($_REQUEST, 'mailTo', '');
$EmailCC=mosGetParam($_REQUEST, 'mailCc', '');
$fromName=mosGetParam($_REQUEST, 'fromName', '');
$deviceId=mosGetParam($_REQUEST, 'deviceId', '');
$appVersion=mosGetParam($_REQUEST, 'appVersion', '1.0');
$osVersion=mosGetParam($_REQUEST, 'osVersion', '');
I hope you can help me.. Thanks in advance :)
I found my solution and my only problem was this line
manager.responseSerializer = [AFImageResponseSerializer serializer];
so I changed it to http
manager.responseSerializer = [AFHTTPRequestSerializer serializer];
and I'll convert the responseObject to utf8 to get the String of it.
success:^(AFHTTPRequestOperation *operation,id responseObject){
NSString *string = [[NString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"Success: %@",string);
}