2013-05-03 34 views
5

Web servisine bir istek göndermek ve yanıtı almak için aşağıdaki kodu kullanıyorum, ancak burada bir seferde iki kez istek aldım, nerede hata yaptığımı bilmiyorum, bu sorundan çıkmama yardım et. şimdiden teşekkürler.İki kez bir istek alın.

NSString *poststr=[NSString stringWithFormat:@"&cname=%@&conname=%@&email=%@",companynametxt.text,contactnametxt.text,contactEmailtxt.text]; 
NSLog(@"poststr %@",poststr); 


NSData *postData = [poststr dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 


NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; 

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: @"web servicess"]]; 
[request setHTTPMethod:@"POST"]; 
[request setHTTPBody:postData]; 

[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self]; 
NSLog(@"DATA%@",theConnection); 
[theConnection release]; 
NSError *error; 
NSURLResponse *response; 
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 

NSString *filenameStr=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; 

NSLog(@"filenameStr %@",filenameStr); 

cevap

0

iki ayrı aramaları

NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self]; 

ve

yapıyoruz
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 

kullanımı ya onlardan biri değil ikisi.