PDA

View Full Version : strange error ! url returning nil !




chhoda
Dec 12, 2008, 08:17 AM
Hi All,

I am getting a strange error.

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"direction" ofType:@"html"];

// NSString *params = [NSString stringWithFormat:@"?dirstr=%@", @"from: 500 Memorial Drive, Cambridge, MA to: 4 Yawkey Way, Boston, MA 02215 (Fenway Park)"/*directioncommand*/];
// filePath = [filePath stringByAppendingString:params];

NSString *fileURLString = [[NSURL fileURLWithPath:filePath] absoluteString];
NSString *params = [NSString stringWithFormat:@"?dirstr=%@", @"from: 500 Memorial Drive, Cambridge, MA to: 4 Yawkey Way, Boston, MA 02215 (Fenway Park)"/*directioncommand*/];
fileURLString = [fileURLString stringByAppendingString:params];
NSURL *fileURL = [NSURL URLWithString:fileURLString];


I am trying to for an url and append parameter to it. unfortunately I am getting url as nil. Is there any way i can see the error ? If i copy paste the string from nslog to the browser it works fine.

thanks and regards
ch



dejo
Dec 12, 2008, 10:06 AM
I would guess it's because the parameter part of your URL contains spaces (i.e. "from: 500 Memorial Drive..."), which isn't allowed. Try calling stringByAddingPercentEscapesUsingEncoding: on it first.