Tuesday, 27 August 2013

NSURLConnection send data twice on server

NSURLConnection send data twice on server

I am creating an iPhone app where i need to send data to server. Using
NSURLConnection I'm able to send data but my data is getting send twice.
And I'm getting response only once. Can anyone suggest why is this
happening
Here is my code
NSURL *url=[NSURL URLWithString:[APIServiceURL geturl]];
NSMutableURLRequest *req=[NSMutableURLRequest requestWithURL:url];
NSString *msgLength=[NSString stringWithFormat:@"%d",[soapMsg1
length]];
[req addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req addValue:@"http://tempuri.org/InsertPostComment"
forHTTPHeaderField:@"SOAPAction"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[soapMsg1 dataUsingEncoding:NSUTF8StringEncoding]];
// Response
NSHTTPURLResponse *urlResponse=nil;
NSError *error;
connection =nil;
connection=[[NSURLConnection alloc]initWithRequest:req
delegate:self];
NSData *responseData;
;
if (connection)
{
responseData=[NSURLConnection sendSynchronousRequest:req
returningResponse:&urlResponse error:&error];
}
else
{
NSLog(@"not connected to server");
}
if ([responseData length]>0)
{
NSString *responseString=[[NSString
alloc]initWithData:responseData
encoding:NSUTF8StringEncoding];
NSLog(@"responseString %@",responseString);
responseString =nil;}
Thanks

No comments:

Post a Comment