I'm trying to accomplish a SOAP request, which successfully returns the desired data in SoapUI, but fails to do so in Xcode using Objective-C for iOS.
// The SOAP message itself.
NSString *soapMessageString = [NSString stringWithFormat:@"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/"
"xmlns:ser=\"http://services.ws.fi.tav.aero\">"
"<soapenv:Header/>"
"<soapenv:Body>"
"<ser:getCurrentFlightList>"
"<code>IST</code>"
"<flightType>INT</flightType>"
"<flightLeg>DEP</flightLeg>"
"</ser:getCurrentFlightList>"
"</soapenv:Body>"
"</soapenv:Envelope>"];
// Calculate the SOAP message length
// NSString *soapMessageLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessageString length]];
// The URL of the SOAP message.
NSURL *soapRequestURL = [NSURL URLWithString:@"<my-SOAP-url>"];
NSMutableURLRequest *soapRequest = [NSMutableURLRequest requestWithURL:soapRequestURL];
// HTTP Headers of the SOAP request
// [soapRequest addValue:@"Wed, 12 Aug 2015 11:58:39 GMT" forHTTPHeaderField:@"Date"];
// [soapRequest addValue:@"chunked" forHTTPHeaderField:@"Transfer-Encoding"];
// [soapRequest addValue:@"HTTP/1.1 200 OK" forHTTPHeaderField:@"#status#"];
// [soapRequest addValue:@"text/xml;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
// [soapRequest addValue:@"keep-alive" forHTTPHeaderField:@"Connection"];
// [soapRequest addValue:@"nginx/1.0.6" forHTTPHeaderField:@"Server"];
// [soapRequest addValue:soapMessageLength forHTTPHeaderField:@"Content-Length"];
// Defining the connection method
[soapRequest setHTTPMethod:@"POST"];
// Combining the SOAP message(as NSData) into the request
[soapRequest setHTTPBody:[soapMessageString dataUsingEncoding:NSUTF8StringEncoding]];
// Making the connection
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:soapRequest delegate:self];
// Check the connection
if (connection) {
_soapData = [NSMutableData data];
} else {
NSLog(@"The connection is null!");
}
The piece of code above makes the request and then the delegate methods of NSURLConnectionDataDelegate
retrieves and displays the data, in this case, the error message.
When the header information is commented out, the error I get is the following: Error reading XMLStreamReader.
And when it's not: 411 Length Required
Is there a difference in iOS in order for the SOAP request to be sent appropriately and retrieved successfully?