I use AFNetworking to post an array comprising the contact details in the device to the server. Given below is my code.
NSDictionary *parameters = @{@"UserContacts": contactsArray};//contactsArray is NSMutableArray
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] init];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager POST:baseUrl parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"RESPONSE : %@",responseObject);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"Error: %@", error.localizedDescription);
}];
The response I got back is
RESPONSE : "failed"
Notice: Undefined index: UserContacts in C:\xampp\htdocs\creator\php\controller\contactsync.php on line 101
The php code is given below
public function insertios(){
if(!isset($_REQUEST['UserContacts'])){
echo json_encode('failed');
$contact = $_REQUEST['UserContacts'];
echo $contact;
}else{
echo json_encode('Success');
}
}
Please tell me where I went wrong.