Creating a Url Compatible String

Discussion in 'iOS Programming' started by roeik, Mar 6, 2009.

  1. macrumors member

    Joined:
    Dec 25, 2008
    #1
    How can i transform a string that contains a url string to a url compatible string? i.e. place all the necessary % symbol, etc. I believe that in java it's encodeURLComponent and in php its urlencode. Is there a similar function on the iPhone?
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    There is an instance method in NSString that holds the answer.
     
  3. thread starter macrumors member

    Joined:
    Dec 25, 2008
    #3
    I tried to use stringByAddingPercentEscapesUsingEncoding: but it doesn't do the job.

    This my problem. I am downloading a file using a url and a urlrequest.
    The url contains web auth in the format http://user:pass@somewebsite.com .

    The problem is that users with special characters in their password can't download the data. If they have a / symbol or % or @, etc they get a bad url error message. It's pretty important i release a fix fast for this. Please help.
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Perhaps you need to consider using CFURLCreateStringByAddingPercentEscapes. Or maybe find a way to percent-escape those characters in the password that are valid URL characters beforehand.
     

Share This Page