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

  • SEARCH
  • Home
  • 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 9230227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:46:20+00:00 2026-06-18T05:46:20+00:00

I tried to pass these characters to server, for example *()$ I have coded

  • 0

I tried to pass these characters to server, for example *()$

I have coded the NSUrl this way:

NSString *partialURL = [NSString stringWithFormat:@"/%@", commentBody];
NSString *fullURL = [NSString stringWithFormat:@"%@%@", CONST_URL, partialURL];
NSString *encStr = [fullURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:encStr];

But then, the commentBody passed in the url still has *()$ things and not encoded into utf8.

What is the correct way to do it?
Thanks!

  • 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-06-18T05:46:22+00:00Added an answer on June 18, 2026 at 5:46 am
    NSString * test = (NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 
                                                                                (CFStringRef)validUrl,
                                                                                NULL, 
                                                                                (CFStringRef)@";/?:@&=$+{}<>,",
                                                                                kCFStringEncodingUTF8);
    

    UPDATE

    Hi @Rendy. Sorry for the quickie reply yesterday. I only had time to past a 1-liner before jumping off and had hoped it would be enough for you to correct the issue you were having.

    You always want to encode the parameters of the URL. IF you have a URL that is a parameter to another URL or embedded in some XML; you’ll want to encode the entire url (which means parameters get double-encoded – because you take a “valid” URL and escape it so it becomes a valid parameter in another URL (ie, : and & get escaped, so parameters don’t mix together.)

    If you like, you can add additional chars to the string below and they’ll be replaced with percent-encoded values. I believe the string below already has you covered for the invalid values.

    Here’s a category on NSString:

    @implementation NSString (encode)
    
    + (NSString*)stringEncodedAsUrlParameter:(NSString *)string
    {
        NSString *newString = NSMakeCollectable(
                    [(NSString *)CFURLCreateStringByAddingPercentEscapes(
                                                                         kCFAllocatorDefault,
                                                                         (CFStringRef)string,
                                                                         NULL, /* charactersToLeaveUnescaped */
                                                                         CFSTR(":/?#[]@!$ &'()*+,;=\"<>%{}|\\^~`"),
                                                                         kCFStringEncodingUTF8
                                                                         ) autorelease]
                    );
    
        if (newString) {
            return newString;
        }
        return @"";
    }
    
    
    - (NSString*)stringByEncodingAsUrlParameter
    {
        return [NSString stringEncodedAsUrlParameter:self];
    }
    
    @end
    

    Call it like this:

    NSString * escapedParameters = [NSString stringEncodedAsUrlParameter:unescapedParameters];
    

    Or:

    NSString * escapedParameters = [unescapedParameters stringByEncodingAsUrlParameter];
    

    Then add your properly escaped parameters to the end of your URL. If you encode the whole URL, you’ll encode the “http://” portion and it won’t work.

    I originally copied the above from ASIHttpRequest, but any bugs added are mine.

    Hope that helps! Best of luck!!

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

Sidebar

Related Questions

I have tried this to pass the information: Form1 frm1 = new Form1(); textBox1.Text
I am trying to pass a variable within a header link. I have tried
I have tried the following code to pass the value from my_view.php(view) to myproject/delete
I tried to pass a string in to get a reversed string. Why can't
I'm working with XML and Flash. I tried to pass XML values to my
I need to pass argument to JNLP dynamically for which I tried using a
Is it possible to pass a variable to a linked .js file? I tried
How do you pass a parameter into an include file? I tried the following
Is it possible to pass some variables to the called function, it tried it
I want to pass the values from MapOverlay class to another class. I tried

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.