Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a request twice?

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);
like image 253
maddysan Avatar asked Nov 12 '22 06:11

maddysan


1 Answers

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.

like image 88
Prabh Avatar answered Nov 15 '22 07:11

Prabh