NSURLConnection sendSynchronousRequest takes too long to respond

I am trying to access data from web services created for a project that I was working on. I create a line to create a request

NSMutableString *sRequest = [[NSMutableString alloc] init]; [sRequest appendString:@"<soapenv:Envelope xmlns:soapenv=\"http:blah blah blah /messages\">"]; [sRequest appendString:@"<soapenv:Header/>"]; [sRequest appendString:@"<soapenv:Body>"]; [sRequest appendString:@"<mes:processActionRequest>"]; [sRequest appendString:@"<ProcessAction>"]; [sRequest appendString:@"</mes:processActionRequest>"]; [sRequest appendString:@"</soapenv:Body>"]; [sRequest appendString:@"</soapenv:Envelope>"]; 

Then I create the url and request

  NSURL *ServiceURL = [NSURL URLWithString:[[NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"webservices" ofType:@"plist"]] valueForKey:@"EndPointURL"]]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:ServiceURL]; [request addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]]; [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate]; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL]; NSTimeInterval duration = [NSDate timeIntervalSinceReferenceDate] - start; NSLog(@"Response Time%.4f",duration); [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; return responseData; 

The problem is that the response time that I typed in the log is always above 20 seconds. But when I hit the same link with the eviware / SoapUI project, it runs for a second, also when the same link is used in the Blackberry project, it works smoothly. I do not understand where I am mistaken. Why is the iPhone a very slow answer. Please help. If I am not clear, please let me know. I will try to elaborate more.

0
source share
2 answers

At the end of the URL, a new line character appeared that caused the problem. Thanks for the support of Andrey.

+3
source

If you are already using code from a background thread, you are better off using asynchronous calls in NSURLConnection.

Do you see the same problem with the asynchronous API?

+1
source

All Articles