简体   繁体   中英

Consider all characters for URL Encode, post data, complete solution iOS

I am sending the data to a server in post body. For which I had used the following code from the Encoding URL Data .

CFStringRef encodedString = CFURLCreateStringByAddingPercentEscapes(
    kCFAllocatorDefault,
    originalString,
    NULL,
    CFSTR(":/?#[]@!$&'()*+,;="),
    kCFStringEncodingUTF8);

Later on I forgot to add one more character in the list which was "'" , a apostrophe. I don't how many character's to add.

Also, if there are some special character's to be submitted to a server with application/x-www-form-urlencoded, what could be a best and stable solution.

It appears that you are missing % on your string.

There is also another solution you can try:

NSString *encodedURL = [rawURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM