开发者

URL Encoding of Characters in a password field

I am trying to pass login credentials to a PHP script that I have in my iPhone app. When I pull a password with special characters the password is missing certain characters especially the percent sign. I am trying to encode the text but even before I send it, the percent sign is missing.

//p_field is a UITextField holding the password: !@#$%^&*()
NSString *tmpPass = [p_field.text stringByAddingPercentEscapesU开发者_StackOverflow社区singEncoding:NSUTF8StringEncoding]; 

NSLog(p_field.text);
NSLog(tmpPass);

This is what appears in the console:

!@#$^&*()

!@2259.719281E-314&*()

Is there any reason why it would be dropping the percent sign?


The first argument to NSLog is a format string, and '%'s have special meaning within the format string. You should instead be doing something like:

NSLog("p_field.text = %@", p_field.text);
NSLog("tmpPass = %@", tmpPass);

(the %@ is the format string sequence for displaying an NSString.)


I tested it on FooBabel.com and it should look like: %21%40%23%24%25%5E%26*%28%29 encoded.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜