I'm developing an iPhone application in Xcode with a login function and I'm having trouble with the following code:
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];
Now there is a member with the password %32dzs3* and the app always gives an error that the password is incorrect. When I NSLog the password it's indeed not the password I typed in the textfield. it looked like this: 50883393zs3* . I also tried this:
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;
}
}
this returns the password as %%%%32dzs3* and the password is right when I NSLog it. still the response is a wrong password response when I run the request. How can I fix this?