Iphone 不解析Web服务
我有这个网络服务。我写了下面的代码,用于从webservice获取数据。但不能获取数据 我试过这个密码Iphone 不解析Web服务,iphone,ios,objective-c,Iphone,Ios,Objective C,我有这个网络服务。我写了下面的代码,用于从webservice获取数据。但不能获取数据 我试过这个密码 -(CGFloat)convertFrom:(NSString*)CountryName { NSString * urlString = [NSString stringWithFormat:@"http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry?CountryName=%@",CountryN
-(CGFloat)convertFrom:(NSString*)CountryName
{
NSString * urlString = [NSString stringWithFormat:@"http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry?CountryName=%@",CountryName];
NSMutableURLRequest * req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
[req setValue:@"http://www.webserviceX.NET" forHTTPHeaderField:@"Host"];
[req setHTTPMethod:@"GET"];
NSData * data = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
NSLog(@"%@",data);
xmlResultString = [[NSMutableString alloc]init];
NSLog(@"%@",xmlResultString);
parser = [[NSXMLParser alloc]initWithData:data];
[parser setDelegate:self];
[parser parse];
return result;
}
- (IBAction)ParseTapped:(id)sender
{
//NSString * urlString = [NSString stringWithFormat:@"http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=%@&ToCurrency=%@",fromCurrency,toCurrency];
[self convertFrom:@"India"];
//return result;
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
[xmlResultString appendString:[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
}
-(void)parserDidEndDocument:(NSXMLParser *)parser
{
result = [xmlResultString floatValue];
NSLog(@"%f",result);
}
-(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
result = -1;
}
foundCharacters:(NSString*)字符串
(NSXMLParser*)解析器
这两个方法没有被调用
但是没有得到数据。我哪里会出错请帮我解决这个问题
提前谢谢。我认为您传递的URL参数不正确。当我尝试你的WS-URL时 它给出一个错误,缺少参数:CountryName 正确的URL参数似乎是CountryName,而不是GetCitiesByCountryResult。这个修改过的URL给出了XML结果。签入WSDL需要为特定WS传递哪些参数
希望有帮助 在convertFrom方法中尝试这样做
NSString *soapMessage = [NSString stringWithFormat:@"<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>
<GetCitiesByCountry xmlns="http://www.webserviceX.NET">
<CountryName>%@</CountryName>
</GetCitiesByCountry>
</soap:Body>
</soap:Envelope>",CountryName];
NSURL *url = [NSURL URLWithString:http://www.webservicex.net/globalweather.asmx];
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://www.webserviceX.NET/GetCitiesByCountry" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSData * data = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil];
NSString*soapMessage=[NSString stringWithFormat:@”
%@
“,国名];
NSURL*url=[NSURL URLWithString:http://www.webservicex.net/globalweather.asmx];
NSMutableURLRequest*theRequest=[NSMutableUrlRequestWithURL:url];
NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapMessage length]];
[theRequest addValue:@“text/xml;charset=utf-8”用于HttpHeaderField:@“Content Type”];
[请求附加值:@”http://www.webserviceX.NET/GetCitiesByCountryforHTTPHeaderField:@“SOAPAction”];
[theRequest addValue:msgLength for HttpHeaderField:@“内容长度”];
[TheRequestSetHttpMethod:@“POST”];
[TheRequestSetHttpBody:[soapMessage数据使用编码:NSUTF8StringEncoding];
NSData*data=[NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil错误:nil];
NSData*data=[NSURLConnection sendSynchronousRequest:req returningResponse:nil错误:nil];NSLog(@“%@”,数据);因此,您甚至无法获取日志数据本身?数据获取但找到字符方法未调用.NSLog(@“%@”,data);(convertFrom方法内部)它打印什么?这样打印…当我查看您的服务时,它看起来像一个WSDL服务。所以像这样使用它谢谢你的回复现在我像这样更改我的url但仍然不起作用url是NSString*urlString=[NSString stringWithFormat:@”;当你说它不起作用时,你得到的错误/日志是什么?-(void)parser:(NSXMLParser*)parser parserrorOccessed:(NSError*))parseError此方法称为not Call found character method..能否打印parseError
说明并检查失败的原因?“操作无法完成。(NSXMLParserErrorDomain错误65。)”发生此错误。。