I want to send a SOAP request to a webservice method. Now I want to send the parameter as an XML input for that request. How can I do it in iPhone? Right now I am sending the request in following way:
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:s开发者_运维知识库oap=\"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]];
But I want to send the parameters in XML format.
Wrap the parameters in the CDATA tag, <![CDATA["parameters"]]>
. This will tell the server not to parse it. Then that data is sent to the service which can parse it as regular xml.
精彩评论