I am using the below code for send a request to web-service and get the response , but here i got the request twice at a time ,i dont where i did mistake,help me to come out from this issue. thanks in advance.
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);
You are making two separate calls
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
and
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
use either one of them not both.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With