ios - Weird output trying to URL encode -
i'm new ios development, , objective-c in general, have created android version of app trying build. current hangup in developing ios version issue having trying url encode string. have tried 2 different methods, both output same weird result.
@implementation nsstring (phantomex) -(nsstring *)urlencode { nslog(self); nsstring *encodedstring = (nsstring*)cfbridgingrelease(cfurlcreatestringbyaddingpercentescapes( null, (cfstringref)self, null, (cfstringref)@"!*'();:@&=+$,/?%#[]", kcfstringencodingutf8 )); nslog(encodedstring); return encodedstring; } @end when called, first nslog outputs fine, un encoded string :
http://api.example.com/?userid=42&cmd={"cmd":"checklogin","data":{ "username" : "joe@example.com", "password" : "verysecurepassword" }}&auth=08fef10b96ac69fcc4bdcf09c3e3d851 whilst second nslog outputs :
2014-03-18 12:52:06.228 phantom[9706:60b] http0x1.1a8a9ap-10470.0000000.000000api.example.com0.0000000.000000userid2610411153 pmd193317 –md23ahecklogin22c 148133072ata23a7-0x1.fcf0808d30dp+0220 10764sername2200x1.2e0c2351534p-1028222joe 5.902543e-310xample.com22c0x1.463c008d30dp-882220 0x1a8321cassword2200x1.70101p-1020222verysecurepassword20a1390253627800088 0x1.006a0c88p-1040uth360473608fef10b96ac69fcc4bdcf09c3e3d851 this separate method produces same result :
-(nsstring *)urlencode { nsstring *characterstoescape = @"!*'();:@&=+$,/?%#[]\" "; nscharacterset *allowedcharacters = [[nscharacterset charactersetwithcharactersinstring:characterstoescape] invertedset]; nsstring *encodedstring = [self stringbyaddingpercentencodingwithallowedcharacters:allowedcharacters]; return encodedstring; } also, realise trying encode whole url, instead of parameters, haven't gotten around changing bit yet. don't think make difference current problem, however.
the problem logging itself, nslog takes first argument format string , parses such. change nslog(@"%@", encodedstring);
Comments
Post a Comment