NSString *sSOAPMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"
http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"
http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"
http://schemas.xmlsoap.org/soap/envelope/\">\n"
"<soapenv:Body>\n"
"<Security>%@</Security>\n"
"<GetMeasuredWaterlevelStationCatalog xmlns=\"
http://www.cjienc.com/CjiencForInstitute/\">\n"
"</GetMeasuredWaterlevelStationCatalog>\n"
"</soap:Body>\n"
"</soap:Envelope>\n",@"950C65C373EA4A1497812FF32D89B10A81863D"
];;
NSURL *sRequestURL = [NSURL URLWithString:@"
http://www.cjienc.com/axis2/services/CjiencForInstitute?wsdl"];
NSMutableURLRequest *myRequest = [NSMutableURLRequest requestWithURL:sRequestURL];
NSString *sMessageLength = [NSString stringWithFormat:@"%d", [sSOAPMessage length]];
[myRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[myRequest addValue: @"
http://www.cjienc.com/CjiencForInstitute/GetMeasuredWaterlevelStationCatalog" forHTTPHeaderField:@"SOAPAction"];
[myRequest addValue: sMessageLength forHTTPHeaderField:@"Content-Length"];
[myRequest setHTTPMethod:@"POST"];
[myRequest setHTTPBody: [sSOAPMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:myRequest delegate:self];
if( theConnection ) {
self.webResponseData = [NSMutableData data];
}else {
NSLog(@"Some error occurred in Connection");
}
GetMeasuredWaterlevelStationCatalog 是请求方法。
打印 Log 如下:
2015-11-18 12:38:13.716 WebServiceDemo[1102:106763] <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="
http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "soapenv"
at [row,col {unknown-source}]: [3,14]</faultstring><detail><Exception>org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "soapenv"
at [row,col {unknown-source}]: [3,14]
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/237018
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.