NSURLConnection sendSynchronousRequest 响应时间过长 [英] NSURLConnection sendSynchronousRequest taking too much time to respond
问题描述
我正在尝试从为我一直从事的项目创建的 Web 服务访问数据.我正在创建一个字符串来创建请求
I am trying to access data from web services created for the project I have been working on. I am creating a string 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>"];
然后我创建一个 URL 并请求
Then I am creating a 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;
问题是,我在 Log 中打印的响应时间总是以某种方式超过 20 秒.但是当我使用 eviware/SoapUI 项目点击相同的链接时,它会在一秒钟内执行,同样当在黑莓项目中使用相同的链接时,它运行顺利.我没有得到,我哪里错了.为什么只有 iPhone 的响应很慢.请帮忙.如果我听起来不清楚,请告诉我.我会尽量详细说明.
The problem is, the response time that I printed in Log always comes to be above 20seconds somehow. But when I hit the same link using eviware/SoapUI project, it executes within a second, also when the same link is being used in blackberry project, it works smoothly. I am not getting, where am I going wrong. Why the response is very slow for iPhone only. Please help. If I am not sounding clear, please let me know. I will try to elaborate more.
推荐答案
在 url 末尾有一个换行符导致了问题.感谢安德鲁的支持.
There was a new line character at the end of url which was causing the problem. Thanks for the support Andrew.
这篇关于NSURLConnection sendSynchronousRequest 响应时间过长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!