Hi,
I have a problem: when i receive the response from the webservice, i receive a xml file, but it contains a header (soap header).
When I use the NSXMLParser, is recognizes 4 elements (soap header) and the other elements (the ones i'm interested in), it recognizes as string.
How can i not receive the soap header?
thanks
iChat:
Rui.Lopes@me.com
Quote:
Originally Posted by tychop
I use the iPhone SDK for webservices. I create a request like the next code fragment shows, and use NSXMLParser for parsing the response. (use NSXMLParser delegates for nested XML tags).
Code:
NSString *path = [NSString stringWithFormat:@"*****.xml", [[NSBundle mainBundle] bundlePath]];
NSString *nakedRequest = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSString *soapMessage = [NSString stringWithFormat:nakedRequest,
@"user",
@"pass",
@"id",
returnType,
origin,
destination,
originDateString,
destinationDateString,
@"Timetable",
@"1",
@"0"
];
NSURL *url = [NSURL URLWithString:@"https://services.*****.com/*****/*****.asmx"];
NSString *messageLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"http://www.*****.com/*****:*****" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:messageLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
soapResponseData = [[NSMutableData data] retain];
}
Works like a charm.
You could even opt to start parsing while the response is still loading.
|