ios - Afnetworking 2 with parameters -
i new ios developments..i want json response web service. when searched found afnetworking that. downloaded , did sample application. need pass parameters service . service takes 2 parameters [username , password]. url
http://myweb.mobile.com/webservices/appointmentservice.asmx/getvaliduser
can please give me code sample how pass parameters service json response ?
i have tried code.. wont take parameters.. people telling afhttpclient.. im using afn 2.0.. there no class call afhttpclient here .. i'm conduced here....please me
nsurl *url = [nsurl urlwithstring:@"https://maps.googleapis.com/maps/api/place/textsearch/json?query=restuarants+in+sydney&sensor=false&key=aizasydn9a-evj875ymxzeinmup7cwbo9yt1w2s"]; nsurlrequest *request = [nsurlrequest requestwithurl:url]; // 2 afhttprequestoperation *operation = [[afhttprequestoperation alloc] initwithrequest:request]; operation.responseserializer = [afjsonresponseserializer serializer]; [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id responseobject) { // 3 self.googleplaces = [responseobject objectforkey:@"results"]; [self.tableview reloaddata]; // nslog(@"json result %@", responseobject); self.weather = (nsdictionary *)responseobject; self.title = @"json retrieved"; [self.tableview reloaddata]; } failure:^(afhttprequestoperation *operation, nserror *error) { // 4 uialertview *alertview = [[uialertview alloc] initwithtitle:@"error retrieving weather" message:[error localizeddescription] delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [alertview show]; }]; // 5 [operation start];
edit :
i have sloved problem using below code segments...
nsdictionary *parameters = [[nsdictionary alloc] initwithobjectsandkeys:@"47", @"caregiverpersonid", nil]; afsecuritypolicy *policy = [[afsecuritypolicy alloc] init]; [policy setallowinvalidcertificates:yes]; afhttprequestoperationmanager *operationmanager = [afhttprequestoperationmanager manager]; [operationmanager setsecuritypolicy:policy]; operationmanager.requestserializer = [afjsonrequestserializer serializer]; operationmanager.responseserializer = [afjsonresponseserializer serializer]; [operationmanager post:@"your full url goes here" parameters:parameters success:^(afhttprequestoperation *operation, id responseobject) { nslog(@"json: %@", [responseobject description]); } failure:^(afhttprequestoperation *operation, nserror *error) { nslog(@"error: %@", [error description]); } ];
try this
-(void)login { nsmutabledictionary *dict=[[nsmutabledictionary alloc]initwithcapacity:3]; [dict setobject:_usernametextfield.text forkey:@"username"]; [dict setobject:_passwordtextfield.text forkey:@"password"]; afhttpclient *client=[[afhttpclient alloc]initwithbaseurl:[nsurl urlwithstring:@""]]; [client registerhttpoperationclass:[afjsonrequestoperation class]]; [client setdefaultheader:@"accept" value:@"application/json"]; client.parameterencoding = afjsonparameterencoding; [client postpath:@"getvaliduser" parameters:dict success:^(afhttprequestoperation *operation, id responseobject) { nsdictionary *op=(nsdictionary *)responseobject; nslog(@"%@",op); } failure:^(afhttprequestoperation *operation, nserror *error) { uialertview *alert=[[uialertview alloc]initwithtitle:message_en message:@"unable login. please try again." delegate:self cancelbuttontitle:ok_en otherbuttontitles:nil, nil]; [alert show]; nslog(@"error.localizeddescription %@",error.localizeddescription); }]; }
note : please fill fields proper values , try. dict input postdata
Comments
Post a Comment