我正在调用一个Web服务来返回各州/省的XML数据。
- (void)viewDidLoad {
[super viewDidLoad];
NSString *titleForURL = self.navigationItem.title;
NSString *path =[NSString stringWithFormat:@"http://myURL/AppointmentWS/CountryStateService.asmx/GetByCountryName?countryName=%@", titleForURL];
//NSString *path =@"http://myURL/CountryStateService.asmx/GetByCountryName?countryName=Canada";
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
if ([statesData count] == 0) {
NSLog(path);
[self parseXMLFileAtURL:path];
}
如果我明确地输入countryName参数,它没有问题。但是如果我使用字符串格式说明符,我会得到一个错误代码5
我认为它可能与url如何编码有关?
思想?
答案 0 :(得分:0)
哪一行产生错误?听起来像是parseXMLFileAtURL。如果是,我会查看两个可能的URL并进行比较。
NSString *path =[NSString stringWithFormat:@"http://myURL/AppointmentWS/CountryStateService.asmx/GetByCountryName?countryName=%@", titleForURL];
NSString *goodPath =@"http://myURL/CountryStateService.asmx/GetByCountryName?countryName=Canada";
if (![path isEqualToString:goodPath])
{
NSLog("Two paths are different:\n%@\n%@\n", path, goodPath);
}
我怀疑编码存在问题。你的标题字符串中可能有一个流氓空间。