Mah*_*abu 0 iphone cocoa-touch objective-c
我是iphone中的Web服务新手.
我需要从.net服务器获取数据.
我接受这个教程
在这个肥皂消息是
NSString *soapMessage = [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"
"<soap:Body>\n"
"<Hello xmlns=\"http://viium.com/\">\n"
"<name>%@</name>\n"
"</Hello>\n"
"</soap:Body>\n"
"</soap:Envelope>\n", nameInput.text
];
Run Code Online (Sandbox Code Playgroud)
但我对此并不了解,
我来自java背景.
在android我的xml字符串是
xml="<MortgageGetLoanOfficerInfo><PhoneNumber>"+getDeviceTelNo()+"</PhoneNumber></MortgageGetLoanOfficerInfo>";
Run Code Online (Sandbox Code Playgroud)
我怎么能用iphone写这个.
任何人都可以发布解决方案.
提前谢谢你.
您正在NSString中正确分配您的soap请求.现在,您必须创建NSMutableURLRequest对象并发送请求,如下所示
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:webServiceUrl];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:yourSoapAction forHTTPHeaderField:@"SOAPAction"];
[req addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[[NSError alloc] init] autorelease];
NSData *webData = [NSURLConnection sendSynchronousRequest:req returningResponse:&urlResponse error:&error];
Run Code Online (Sandbox Code Playgroud)
现在使用任何xml解析器解析webData.我通常更喜欢NSXMLParser
希望这有帮助..