views:

57

answers:

1

I am calling a web service to return XML data for states/provinces of countries.

- (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];
}

If I explicitly put the countryName parameter, it works no problem. But if I use the string format specifier, I get an Error Code 5

I think it may have to do with how the url gets encoded?

Thoughts?

A: 

Which line is generating the error? It sounds like parseXMLFileAtURL. If it is, I would look at the two possible URLs and compare them.

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);
}

I doubt that there is an issue with encoding. You may have a rogue space in your title string.

Epsilon Prime
hmm...when I log the array that gets returned, it appears there is a "/n " at the end of each item...curses!
rson
I didn't do it above but I find it helpful to log strings inside square brackets to make it easier to find trailing whitespace: NSLog("Two paths are different:\n[%@]\n[%@]\n", path, goodPath);
Epsilon Prime