我正在尝试从为我一直在从事的项目创建的 Web 服务中访问数据。我正在创建一个字符串来创建一个请求
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 并请求
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 的响应速度很慢。请帮忙。如果我听起来不清楚,请告诉我。我将尝试详细说明。