Your query component needs to be "percent escaped". Furthermore, your query component may be special, in that it's structure is hierarchical. That is, a server will need to implement custom code to handle this.
The standard way for a server to decode a query component of a URL is to use the same algorithm which is defined for the decoding of a body of a "application/x-www-form-urlencoded" request. The corresponding encoding algorithm employed by the client is defined here:
application/x-www-form-urlencoded encoding algorithm
(Note: The query component is everything after the question mark '?'
up until a hash character '#'
!)
However, this encoding algorithm may produce percent escapes for characters that are in the "Unreserved" character set of an URL, according RFC 3986, namely the tilde ~ character. Characters in the "Unreserved" character set don't need to be escaped. More strictly, due to implications in URI comparison implementations, RFC 3986 makes this recommendation:
"For consistency, percent-encoded octets in the ranges of ALPHA (%41-%5A and %61-%7A), DIGIT (%30-%39), hyphen (%2D), period (%2E), underscore (%5F), or tilde (%7E) should not be created by URI producers".
Thus, a slightly modified implementation which excludes the tilde '~'
from escaping may yield the best results.
The following code encodes the name or the value of a parameter. Note that parameters must be separated by a '&', and the name and value must be separated by a '='.
static NSString* form_urlencode_rfc3986(NSString* s) {
CFStringRef charactersToLeaveUnescaped = CFSTR(" ");
//CFStringRef legalURLCharactersToBeEscaped = CFSTR("!$&'()+,/:;=?@~");
// Modified for urls (excluding '~'):
CFStringRef legalURLCharactersToBeEscaped = CFSTR("!$&'()+,/:;=?@");
NSString *result = CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(
kCFAllocatorDefault,
(__bridge CFStringRef)s,
charactersToLeaveUnescaped,
legalURLCharactersToBeEscaped,
kCFStringEncodingUTF8));
return [result stringByReplacingOccurrencesOfString:@" " withString:@"+"];
}
Example:
Given your example URL, the query component consists of one parameter:
parameter name: "do"
parameter value: "/webservice/whisper/login_ms@gmail.com/password_ms/action_stirwhisper/whisperstirdata_{"feed_id":"89","say_something":"pqrst","privacy":0}"
The encoded query component will then look as below:
do=%2Fwebservice%2Fwhisper%2Flogin_ms%40gmail.com%2Fpassword_ms%2Faction_stirwhisper%2Fwhisperstirdata_%7B%22feed_id%22%3A%2289%22%2C%22say_something%22%3A%22pqrst%22%2C%22privacy%22%3A0%7D