Search code examples
objective-ciosnsurlconnectionnsurlnsurlrequest

iOS Bad URL for NSUrlConnection


I have a url in an NSString called myUrl. When I NSLog myUrl I see the following:

http://dl.dropbox.com/u/57665723%2FChocolatesRUs%2FJellies%2FUn-sugared%2Fgen%20no%20sugar.pdf

I then try connecting using this url as follows:

NSURL* url = [ NSURL URLWithString:nextFileURL ];
NSMutableURLRequest* request =  [ [ NSMutableURLRequest alloc ] initWithURL: url ];
NSURLConnection* conn = [ [ NSURLConnection alloc ] initWithRequest: request delegate: self ];

I am getting the following error:

errorcode=-1000, error=Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x27e540 {NSUnderlyingError=0x26d800 "bad URL", NSLocalizedDescription=bad URL}

I have tried using

NSString* myUrl = [myUrl stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

but this doesn't work either.

Can anyone see the problem?


Solution

  • Maybe you can escape your url with stringByAddingPercentEscapesUsingEncoding instead of stringByReplacingPercentEscapesUsingEncoding.