【发布时间】:2014-01-23 12:31:39
【问题描述】:
我可以使用 NSMutableURLRequest 和 NSURLConnection 连接到 SOAP Web 服务,如下所示:
NSString *soapMessage = [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>"
"<CelsiusToFahrenheit xmlns=\"http://www.w3schools.com/webservices/\">"
"<Celsius>140.0</Celsius>"
"</CelsiusToFahrenheit>"
"</soap:Body>"
"</soap:Envelope>"];
NSData *soapData = [soapMessage dataUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:@"http://w3schools.com/webservices/tempconvert.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://www.w3schools.com/webservices/CelsiusToFahrenheit" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:@"www.w3schools.com" forHTTPHeaderField:@"Host"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:soapData];
我怎样才能使用AFNetworking 或STHTTPRequest 做同样的事情?
【问题讨论】:
-
您最初的问题本身并不是一个明确的问题,但我已对其进行了进一步的重组,因此它确实提出了一个真正的问题。结果,我认为它可以重新打开。与其说是你自己回答的问题,不如说是当你创建自我回答的问题时,问题必须是一个明确的问题。
-
@Brad Larson - 谢谢
标签: ios objective-c iphone afnetworking sthttprequest