ios - post data and get successful response -


this question has answer here:

hi new iphone development can 1 explain me how post data url , successful response form below example code ...

-(ibaction)clicked:(id)sender{     nsstring *cidstring = cid.text;      nsurl *url = [nsurl urlwithstring:@"http://localhost:8080/test/?"];     nsstring *postdata = [nsstring stringwithformat:@"companyid=%@",cidstring];      nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:[url standardizedurl]                                                            cachepolicy:nsurlrequestreloadignoringlocalcachedata timeoutinterval:60];      [request sethttpmethod:@"post"];     [request setvalue:@"application/x-www-form-urlencoded; charset=utf-8" forhttpheaderfield:@"content-type"];     [request sethttpbody:[postdata datausingencoding:nsutf8stringencoding]];      [self startconnection:(nsmutableurlrequest *)request];      if([self.result isequaltostring:@"new alert"])     {         cid.text = @"scuess";     }  } 

and startconnection follows

- (void)startconnection:(nsmutableurlrequest *)request {      [self.connection cancel];      nsmutabledata *data = [[nsmutabledata alloc] init];     self.receiveddata = data;     self.result = [[nsstring alloc] initwithdata:data encoding:nsasciistringencoding];     nslog(@"receiveddata: %@", [[nsstring alloc] initwithdata:receiveddata encoding:nsasciistringencoding]);       self.connection = [[nsurlconnection alloc] initwithrequest:request delegate:self];      if (self.networkerroralert) {         nslog(@"connection fail");      }      [self.connection start]; } 

can please me...

-(void)sendrequest {

nsstring *tempusername = txtusername.text; nsstring *tmppassword = txtpassword.text; nsstring *tempurllogin = [staticstrings urllink]; nsstring *tmpurl = [nsstring stringwithformat:@"http://example.com/validateservice?", tempurllogin]; nsstring *connect; connect = [nsstring stringwithformat:@"%@emailaddress=%@&password=%@", tmpurl,tempusername,tmppassword];  responsedata = [[nsmutabledata data] retain]; nsurl *url = [[nsurl alloc] initwithstring:connect]; nsurlrequest *request = [nsurlrequest requestwithurl:url]; [[nsurlconnection alloc] initwithrequest:request delegate:self];  [url release]; [request release]; 

}


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -