NSURL *url = [NSURL URLWithString:@"http://192.168.1.56/AMSP/AMSPWS.asmx"];
NSString *soapMsg=[NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<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/\">"
"<soap:Body>"
"<PostXMLStr xmlns=\"http://tempuri.org/\">"
"<cust>%@</cust>"
"<tran>%@</tran>"
"<ret>%@</ret>"
"<ppay>%@</ppay>"
"<recp>%@</recp>"
"<sCode>%@</sCode>"
"<companyShortName>%@</companyShortName>"
"<companyCode>%@</companyCode>"
"</PostXMLStr>"
"</soap:Body>"
"</soap:Envelope>",cust,trans,RETURNS,prepayment,receipt,spcode1,companyShortName,companyCode];
NSMutableURLRequest *requests = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:5];
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMsg length]];
[requests setHTTPMethod:@"POST"];
[requests addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[requests addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[requests addValue:@"http://tempuri.org/PostXMLStr" forHTTPHeaderField:@"SOAPAction"];
[requests setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding ]];
NSURLResponse *response;
NSError *error = nil;
NSData *data =[[NSMutableData alloc]init];
data = [NSURLConnection sendSynchronousRequest:requests returningResponse:&response error:&error];
NSString *stringSoap;
stringSoap = [[NSString alloc] initWithData:data encoding:NSMacOSRomanStringEncoding];
NSDictionary *headers = [(NSHTTPURLResponse *)response allHeaderFields];
我是通过目标 C 连接 WebService 的新手。我不知道如何检查 XML 是否连接到 WebService。当我打印 stringSoap 时,我没有得到任何价值。我不知道这是调用 XML 的正确方法。如何检查 XML 是否连接到 WebService。任何帮助将不胜感激。提前致谢。