2013-05-03 80 views
5

我正在使用下面的代碼發送一個請求到Web服務並獲得響應,但是在這裏我一次收到兩次請求,我不知道我錯了哪裏,幫助我從這個問題中解脫出來。提前致謝。獲取兩次請求?

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); 

回答

0

你正在兩個單獨的呼叫

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

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

使用其中任意一個不能同時使用。