0

我想向 Web 服务方法发送 SOAP 请求。现在我想将参数作为该请求的 XML 输入发送。我怎样才能在 iPhone 中做到这一点?现在我正在通过以下方式发送请求:

NSString *soapMessage =
@"<?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"
"<GetCustomerInfoXML xmlns=\"http://qa2.alliancetek.com/phpwebservice\">\n"
"<id><customer><id>1</id></customer></id>"
"</GetCustomerInfoXML>"
"</soap:Body>\n"
"</soap:Envelope>";
NSLog(@"%@",soapMessage);

NSURL *url = [NSURL URLWithString:@"http://qa2.alliancetek.com/phpwebservice/index.php"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://qa2.alliancetek.com/phpwebservice/index.php//GetCustomerInfoXML" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

但我想以 XML 格式发送参数。

4

1 回答 1

2

将参数包装在 CDATA 标记中,<![CDATA["parameters"]]>. 这将告诉服务器不要解析它。然后将该数据发送到可以将其解析为常规 xml 的服务。

于 2010-12-16T19:05:45.803 回答