iphone - NSMutableURLRequest sends once on localhost, but twice on web -
hey everbody, im getting trouble here. have button makes connection php, updating database. well, im getting curious problem here.
when set update local db, sends data 1 time. but, when set test on web, updates twice.
same error giving me error message. local doesnt gives me, online does.
why?
thanks! here goes code:
nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl: [nsurl urlwithstring:@"http://localhost/dev/mcomm/pedido.php"]]; [request sethttpmethod:@"post"]; nsstring *poststring = [[nsstring alloc] initwithformat:@"nome=%@&email=%@&endereco=%@&produto=%@&marca=%@&preco=%@&codigo=%@&variacao=%@&parcelas=%@&valorparcelas=%@&cartao=%@&numcartao=%@&codcartao=%@&venccartao=%@&nomecartao=%@", self.shareddata.datanome, self.shareddata.dataemail, endereco, self.shareddata.dataprod, self.shareddata.datamarca, self.shareddata.datapreco, self.shareddata.datacodigo, self.shareddata.datavariacao, parcelanum.text, parcelaresultante.text, self.shareddata.cartao, numerodocartao.text, codigodocartao.text, validadecartao.text, impressocartao.text]; nslog(@"enviado"); [request sethttpbody:[poststring datausingencoding:nsutf8stringencoding]]; //[request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; [uiapplication sharedapplication].networkactivityindicatorvisible = yes; //get response nshttpurlresponse* urlresponse = nil; nserror *error = [[nserror alloc] init]; nsdata *responsedata = [nsurlconnection sendsynchronousrequest:request returningresponse:&urlresponse error:&error]; nsstring *result = [[nsstring alloc] initwithdata:responsedata encoding:nsutf8stringencoding]; [self.view addsubview:loadingrequest]; loadingrequest.backgroundcolor = [uicolor clearcolor]; loadingrequest.center = self.view.center; nslog(@"response code: %d", [urlresponse statuscode]); nslog(@"res: %@", result); if ([urlresponse statuscode] > 400) { uialertview *alert = [[uialertview alloc] initwithtitle:@"erro" message:@"falha ao conectar com o servidor." delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [uiapplication sharedapplication].networkactivityindicatorvisible = no; [alert show]; [alert release]; } else if ([result isequaltostring:@"erro"]) { uialertview *alert = [[uialertview alloc] initwithtitle:@"erro" message:@"não foi possível realizar seu pedido. tente novamente mais tarde." delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]; [uiapplication sharedapplication].networkactivityindicatorvisible = no; [alert show]; [alert release]; } else { finalizarviewcontroller *telafinal = [[[finalizarviewcontroller alloc] initwithnibname: nsstringfromclass([finalizarviewcontroller class]) bundle:nil] autorelease]; [self.navigationcontroller pushviewcontroller:telafinal animated:yes]; [self navigationcontroller].navigationbarhidden = yes; [uiapplication sharedapplication].networkactivityindicatorvisible = no; [self.loadingrequest removefromsuperview]; }
Comments
Post a Comment