cn't download mp3 file

Discussion in 'iOS Programming' started by erritikamathur, Nov 25, 2009.

  1. macrumors newbie

    Joined:
    Sep 23, 2009
    #1
    i m trying to download mp3 file from server but i m not getting any data

    i m getting error as
    Error {
    NSLocalizedDescription = "bad URL";
    NSUnderlyingError = Error Domain=kCFErrorDomainCFNetwork Code=-1000 UserInfo=0x1183ac0 "bad URL";
    }
    here is my code----
    Code:
    sender=@"http://sound13.mp3pk.com/indian/7days/7days01(www.songs.pk).mp3";
    NSMutableURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:sender]
                                                  cachePolicy:NSURLRequestUseProtocolCachePolicy
                                              timeoutInterval:60.0];
         // create the connection with the request
        // and start loading the data
    	NSURLResponse *res=NULL;
    	NSError *error=NULL;
    	NSData *data=[NSURLConnection sendSynchronousRequest:theRequest returningResponse:&res error:&error];
    	NSLog(@"download data---%@",[res URL]);
    i need to store the data received from server.i cn't figure where i m missing&if i provided any path with .wma file or anything else it gets downloaded
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    You cannot use quite a few characters in a URL. See here.

    You need to encode your URL. There is an obvious method of NSString. I'll leave it to you to open the documentation and find it.
     
  3. thread starter macrumors newbie

    Joined:
    Sep 23, 2009
    #3
    I m aware that we can't use few characters in URL,so i m sending encoded URlL only by converting string url into URL by method [NSURL URLWithString:sender]

    then also i m not able to download mp3 file.
    if in case i send path for any other type of file i can easily download it my same method.
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State

Share This Page