ios - How to use setHTTPBody from UITextField input -


i using mycontacts restful api integrate in application. now, want use username , password entered uitextfield not manually. not know, how in sethttpbody. suggestions?

nsurl *url = [nsurl urlwithstring:@"https://api.addressbook.io/v1/login"];  nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url]; [request sethttpmethod:@"post"];  [request setvalue:@"application/json" forhttpheaderfield:@"content-type"];  //here want use username , password obtained uitextfield. [request sethttpbody:[@"{\n  \"username\": \"enter username\",\n  \"password\": \"enterpassword\",\n  \"client\": \"apiary\"\n}" datausingencoding:nsutf8stringencoding]];  nsurlsession *session = [nsurlsession sharedsession]; nsurlsessiondatatask *task = [session datataskwithrequest:request                                         completionhandler:                               ^(nsdata *data, nsurlresponse *response, nserror *error) {                                    if (error) {                                       // handle error...                                       return;                                   }                                    if ([response iskindofclass:[nshttpurlresponse class]]) {                                       nslog(@"response http status code: %ld\n", (long)[(nshttpurlresponse *)response statuscode]);                                       nslog(@"response http headers:\n%@\n", [(nshttpurlresponse *)response allheaderfields]);                                   }                                    nsstring* body = [[nsstring alloc] initwithdata:data encoding:nsutf8stringencoding];                                   nslog(@"response body:\n%@\n", body);                               }]; [task resume]; 

i guess not want have button click on webservice should called. can set delegate both uitextfield , use delegate method

- (void)textfielddidendediting:(uitextfield *)textfield; 

what delegate method called each time move out of textfield. here can check whether user have entered both textfield , set http body.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -