我正在使用 Soap Web 服务从服务器下载数据。下载数据时设备像闪光灯一样闪烁。我正在使用同步请求来获取数据。我找不到它闪现的原因。请帮帮我,在此先感谢。
这是代码:
NSString *msgString = [[NSString alloc] initWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
"xmlns:xsd=\"http://http://www.w3.org/2001/XMLSchema\" "
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
"<soap:Body>"
"<GetCategories xmlns=\"http://tempuri.org/\"/>"
"</soap:Body>"
"</soap:Envelope>"];
NSURL *url = [NSURL URLWithString:[DefaultSettings getLink]];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30];
//---set the various headers---
NSString *msgLength = [NSString stringWithFormat:@"%d", [msgString length]];
[req addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://tempuri.org/GetCategories" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
//---set the HTTP method and body---
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[msgString dataUsingEncoding:NSUTF8StringEncoding]];
NSError *error;
NSURLResponse *response;
NSData *webData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
xmlParser = [[NSXMLParser alloc] initWithData:webData];
[xmlParser setDelegate:self];
[xmlParser setShouldProcessNamespaces:NO];
[xmlParser setShouldReportNamespacePrefixes:NO];
[xmlParser setShouldResolveExternalEntities:YES];
[xmlParser parse];
在此之后,我正在解析数据。同样的方法,我一一调用了8个soap服务。