创建了一个扩展名为.php的Web服务,我通过soap传递参数。但它的回报是出于我的理解。我还使用正确的输入检查RestClient,然后返回实际输出。这在代码中没有正确进行。可能出了什么问题?
输入的xml结构是,
<?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:Header>
</soap:Header>
<soap:Body>
<getUpdates>
<user_location></user_location>
<application_type>FC</application_type>
<last_updated_date>2014-11-25</last_updated_date>
<platform>Android</platform>
</getUpdates>
</soap:Body>
</soap:Envelope>
我的网络服务方法是,
-(void) notifyDatacalled
{
NSString * post= @"<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:Header></soap:Header><soap:Body><getUpdates><user_location>new york</user_location><application_type>free</application_type><last_updated_date>2014-12-12</last_updated_date><platform>ios</platform></getUpdates></soap:Body></soap:Envelope>";
NSURL *url = [NSURL URLWithString:@"http://game.techone.com/webservices/service.php"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setTimeOutSeconds:30];
[request setDelegate:self];
[request setPostBody:[[post dataUsingEncoding:NSUTF8StringEncoding] mutableCopy]];
[request addRequestHeader:@"Content-Type" value:@"text/xml"];
[request addRequestHeader:@"Content-Length" value:[NSString stringWithFormat:@"%d",[post length]]];
[request addRequestHeader:@"SOAPAction" value:@"getUpdates"];
[request setPostLength:[post length]];
[request setRequestMethod:@"POST"];
[request startSynchronous];
NSError *error = [request error];
if (error)
{
}
else
{
NSString *XmlResult = [NSString stringWithFormat:@"%@",[request responseString]];
NSDictionary *dictioneryResult = [XMLReader dictionaryForXMLString:XmlResult error:nil];
}
}
我得到的回应是,
"SOAP-ENV:Envelope" = {
"SOAP-ENV:Body" = {
"ns1:getUpdatesResponse" = {
return = {
"SOAP-ENC:arrayType" = "xsd:anyType[0]";
"xsi:type" = "SOAP-ENC:Array";
};
"xmlns:ns1" = "http://schemas.xmlsoap.org/soap/envelope/";
};
};
"SOAP-ENV:encodingStyle" = "http://schemas.xmlsoap.org/soap/encoding/";
"xmlns:SOAP-ENC" = "http://schemas.xmlsoap.org/soap/encoding/";
"xmlns:SOAP-ENV" = "http://schemas.xmlsoap.org/soap/envelope/";
"xmlns:xsd" = "http://www.w3.org/2001/XMLSchema";
"xmlns:xsi" = "http://www.w3.org/2001/XMLSchema-instance";
};
答案 0 :(得分:0)
尝试添加
[request addRequestHeader:@"Accept" value:@"text/xml"];
到您的网络服务请求。您正在调用的REST服务默认为json。许多人经常根据请求返回XML。