ios - AFNetworking 2.0 Send Post Request with array of dictionary Parameters -


i want try post parameter in following api parameter not getting passed properly, , response received gives message that, data required. can please sort out problem.

my url

forapp.com/api/getcontacts.php?data=[ {"name":"abc","phone":"1234567890"},{"name":"kate bell","phone":"9925992599"} ]

so how can pass type of request api

   afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager];     nsdictionary *params = @{@"name": @"hello",                              @"phone": @"1234567890"};     nslog(@"dict %@",params);     manager.responseserializer.acceptablecontenttypes = [manager.responseserializer.acceptablecontenttypes setbyaddingobject:@"text/html"];  [manager post:@"http://forapp.com/api/getcontacts.php" parameters:params success:^(afhttprequestoperation *operation, id responseobject) {     nslog(@"json: %@", responseobject);  } failure:^(afhttprequestoperation *operation, nserror *error) {     nslog(@"error: %@", error);  }]; 

just add

step-1

// create dictionary of {"name":"abc","phone":"1234567890"},{"name":"kate bell","phone":"9925992599"}  nsdictionary *params = @{@"name": @"hello",                          @"phone": @"1234567890"}; 

step-2

//create 1 array of output [ {"name":"abc","phone":"1234567890"},{"name":"kate bell","phone":"9925992599"} ]  nsmutablearray *arr = [nsmutablearray arraywithobjects:params,nil]; 

step-3

// convert object json string nserror *error = nil; nsstring *createjson = [[nsstring alloc] initwithdata:[nsjsonserialization datawithjsonobject:objectsincart                                                                                 options:nsjsonwritingprettyprinted                                                                                   error:&error]                                        encoding:nsutf8stringencoding]; 

step-4

//create 1 dictionary send data data=[ {"name":"abc","phone":"1234567890"},{"name":"kate bell","phone":"9925992599"} ]   nsdictionary *pardsams = @{@"data": createjson}; 

step-5

  // start request   afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager];      nslog(@"dict %@",pardsams);     manager.responseserializer.acceptablecontenttypes = [manager.responseserializer.acceptablecontenttypes setbyaddingobject:@"text/html"];  [manager post:@"http://forapp.com/api/getcontacts.php" parameters:pardsams success:^(afhttprequestoperation *operation, id responseobject) {     nslog(@"json: %@", responseobject);  } failure:^(afhttprequestoperation *operation, nserror *error) {     nslog(@"error: %@", error);  }]; 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -