iOS

时间:2015-08-12 13:50:08

标签: ios objective-c soap

我正在尝试完成SOAP请求,该请求在SoapUI中成功返回所需数据,但在Xcode中使用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!");
}

上面的代码片段发出请求,然后NSURLConnectionDataDelegate的委托方法检索并显示数据,在本例中为错误消息。

当标题信息被注释掉时,我得到的错误如下:Error reading XMLStreamReader.

当它不是:411 Length Required

iOS中是否存在差异,以便成功发送和检索SOAP请求?

0 个答案:

没有答案