我正在开发在Xcode一个登录功能的iPhone应用程序,我有下面的代码的麻烦:密码与百分比符号总是错的iPhone
NSString *post = [NSString stringWithFormat:@"username=%@&password=%@",[NSString stringWithFormat:@"%@",username],password];
NSLog(post);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding];
[request setHTTPMethod:@"POST"];
[request addValue:[NSString stringWithFormat:@"%@",username] forHTTPHeaderField:@"username"];
[request addValue:password forHTTPHeaderField:@"password"];
[request setHTTPBody:postData];
action = @"token";
NSURLConnection *connection;
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
现在有与密码%的成员32dzs3 *和应用程序总是给出错误,密码不正确。当我NSLog密码时,它确实不是我在文本框中输入的密码。它看起来像这样:50883393zs3 *。我也试过这样:
for(int i = 0; i < [password length];i++){
if([password characterAtIndex:i] == '%'){
NSString *temporarypw = [password substringWithRange:NSMakeRange(0, i)];
password = [NSString stringWithFormat:@"%@%%%%%@",temporarypw,[password substringWithRange:NSMakeRange((i+1), (password.length - i -1))]];
break;
}
}
这个返回密码%%%% 32dzs3 *和密码是正确的,当我的NSLog它。当我运行请求时,响应仍然是错误的密码响应。我怎样才能解决这个问题?
你的意思是在你的应用程序中,密码是以明文形式发送的,不能转义?哎哟。我不想成为你的用户之一。 – jv42 2012-01-12 13:59:41