Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 869569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:19:43+00:00 2026-05-15T10:19:43+00:00

I have to POST data to a php page from an Iphone application, so

  • 0

I have to POST data to a php page from an Iphone application, so i need to encode the parameters properly, converting the special characters…

Specifically i need to send the UDID of the iphone.

I’ve found many helps on the web to encode the String to pass as parameter, but i got a strange error.

I’m using this function:

- (NSString *)URLEncodeString:(NSString *)string { 

NSString *result =
   (NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 
    (CFStringRef)string, NULL, CFSTR("'\"?=&+<>;:-"), kCFStringEncodingUTF8);

return [result autorelease];}

it seems correct but when i use it, the result isn’t what i expect for.

This is the code:

UIDevice *device = [UIDevice currentDevice];
NSString *uniqueIdentifier = [device uniqueIdentifier];

NSLog(uniqueIdentifier);
NSLog([self URLEncodeString:uniqueIdentifier]);

and this is the Log generated when i hit this code:

2010-06-23 21:58:51.671 provaNavigation[2343:20b] 00000000-0000-1000-8000-0013775CE6D2
2010-06-23 21:58:51.672 provaNavigation[2343:20b] 0000000010003900009080176010001273086780001283520013775CE6D2

and again:

2010-06-23 21:59:25.614 provaNavigation[2343:20b] 00000000-0000-1000-8000-0013775CE6D2
2010-06-23 21:59:25.615 provaNavigation[2343:20b] 000000001000390000908192801000-18000912258750013775CE6D2

and again:

2010-06-23 21:59:40.848 provaNavigation[2343:20b] 00000000-0000-1000-8000-0013775CE6D2
2010-06-23 21:59:40.849 provaNavigation[2343:20b] 000000001000390000908866081000-18000912239630013775CE6D2

and again…

I get a different value every time and never correct with the right %number.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:19:43+00:00Added an answer on May 15, 2026 at 10:19 am

    I’ve come across problems URL encoding before, so I ended up writing a category on NSString to properly encode URLs:

    - (NSString *) URLEncodedString {
      NSMutableString * output = [NSMutableString string];
      const char * source = [self UTF8String];
      int sourceLen = strlen(source);
      for (int i = 0; i < sourceLen; ++i) {
        const unsigned char thisChar = (const unsigned char)source[i];
        if (thisChar == ' '){
          [output appendString:@"+"];
        } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' || 
               (thisChar >= 'a' && thisChar <= 'z') ||
               (thisChar >= 'A' && thisChar <= 'Z') ||
               (thisChar >= '0' && thisChar <= '9')) {
          [output appendFormat:@"%c", thisChar];
        } else {
          [output appendFormat:@"%%%02X", thisChar];
        }
      }
      return output;
    }
    
    - (NSString *) URLDecodedString {
      NSString * spacedDecoded = [self stringByReplacingOccurrencesOfString:@"+" withString:@" "];
      return [spacedDecoded stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    }
    

    There are a couple notes about this:

    1. This will encode spaces as “+”
    2. This encodes everything except a-z (upper and lowercase), numbers, period, hyphen, underscore, and tilde
    3. This will properly encode unicode characters as multiple octets. For example, I can do:

      NSString * enc = [@"http://example.com/?data=÷¡¿" URLEncodedString];
      NSLog(@"%@", enc);
      NSLog(@"%@", [enc URLDecodedString]);

      Which will properly log:

      Testing.m:65 main() http%3A%2F%2Fexample.com%2F%3Fdata%3D%C3%B7%C2%A1%C2%BF
      Testing.m:66 main() http://example.com/?data=÷¡¿

    EDIT
    I copied and pasted it into an empty project, like this:

    NSString * string = @"00000000-0000-1000-8000-0013775CE6D2";
    NSString *result = (NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR("'\"?=&+<>;:-"), kCFStringEncodingUTF8);
    NSLog(@"encode? %@", result);
    result = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"decode? %@", result);
    NSLog(@"equal? %d", [string isEqual:result]);
    

    And it logs:

    Testing[62541:a0f] encode? 00000000%2D0000%2D1000%2D8000%2D0013775CE6D2
    Testing[62541:a0f] decode? 00000000-0000-1000-8000-0013775CE6D2
    Testing[62541:a0f] equal? 1
    

    The reason your code isn’t working is because you’re logging the string as the format string, which means it’s seeing the %2 stuff and trying to replace it with other things. Observe:

    NSString * string = @"00000000-0000-1000-8000-0013775CE6D2";
    NSString *result = (NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, CFSTR("'\"?=&+<>;:-"), kCFStringEncodingUTF8);
    NSLog(@"%@", result);
    NSLog(result);
    

    Logs:

    Testing[62585:a0f] 00000000%2D0000%2D1000%2D8000%2D0013775CE6D2
    Testing[62585:a0f] 00000000879923200001897296640100041968968000 00013775CE6D2
    

    So the string is getting properly encoded, but you’re just logging it incorrectly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 424k
  • Answers 424k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The first and probably most important step is to program… May 15, 2026 at 11:54 am
  • Editorial Team
    Editorial Team added an answer You need to modify app.yaml in your project, setting application/octect-stream… May 15, 2026 at 11:54 am
  • Editorial Team
    Editorial Team added an answer logic.scala code package logic class Logic{ def hello = "hello"… May 15, 2026 at 11:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.