Problem converting urlString to NSURL in iphone sdk

I have a string first method calls with a timestamp nil value, and I get the converted string in url. At one time, when I click the download button for more results again, the method calls with the timestamp value assigned to it. but the URL of the string is not converted to NSURL iam, getting a null value in it.

-(NSMutableArray*)getTextMessagesArray:(NSString *)endTimestamp { printf("\n endtimestamp value...%s",[endTimestamp UTF8String]); NSString *urlString = @"http://123.237.186.221:8080/upload/textRequest.jsp"; urlString = [urlString stringByAppendingString:@"?beginTimestamp="]; urlString = [urlString stringByAppendingString:@"&endTimestamp="]; if([endTimestamp length]>0) { urlString = [urlString stringByAppendingString:endTimestamp]; } printf("\n &*(*(((urlString...%s",[urlString UTF8String]); NSURL* aUrl = [NSURL URLWithString:urlString]; NSLog(@"url in appdelegaare in text...%@",aUrl); [textParser parseXMLFileAtURL:aUrl]; textMessagesList = [textParser getTextMessagesList]; printf("\n textMessagesList Count in appDelegate....%d",[textMessagesList count]); return textMessagesList; } 

The result that I get on the console is:

  &*(*(((urlString...http://123.237.186.221:8080/upload/textRequest.jsp?endTimestamp=2010-10-08 16:20:47.0 url in appdelegaare in text...(null) 

Can someone tell me why this is happening

Any help would be greatly appreciated.

Thanks to everyone, Monish.

+4
source share
1 answer

Your problem is that valid URLs cannot contain spaces. You want to do something in the following lines:

 NSString *escapedUrlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; // escapedUrlString should be "http://123.237.186.221:8080/upload/textRequest.jsp?endTimestamp=2010-10-08%2016:20:47.0" NSURL *aUrl = [NSURL URLWithString:escapedUrlString]; 

It could be what you wanted.

+17
source

All Articles