2010-06-15 109 views
0

我想發送肥皂請求到webservice方法。現在我想發送該參數作爲該請求的xml輸入。所以PLZ任何人都可以給我一個關於如何在iPhone中做到這一點的想法?現在我以下列方式發送請求:肥皂web服務請求在iphone中的xml參數

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格式發送參數。所以我該怎麼做?

回答

2

將參數包裝在CDATA標籤<![CDATA["parameters"]]>中。這會告訴服務器不要解析它。然後,數據被髮送到可以解析爲常規xml的服務。