In my app I want to check the Authentication For Login. But when I post request I don't know if my request has reached the server.
Here is my code...
-(void)clearsession
{
NSString *username = @"tiger@gmail.com" ;
NSString *password = @"password";
NSURL *aUrl = [NSURL URLWithString:@"http://developer.b24solutions.com/grocery/MyLogin.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:0.0];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
NSString *postString = [NSString stringWithFormat:@"username=%@ password=%@",username,password];
NSLog(@"string that post:%@",postString);
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *clearSession = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[clearSession start];
NSLog(@"%@",clearSession);
if(clearSession){
NSLog(@"data send");
}
else
{
NSLog(@"connection failed");
}
}
and rather NSURLConnection method are same as defined.
In this app I send the username and password in a JSON format. If the user name is already register then it receives response status=1
otherwise status=0
. but when I send registered username and password then the response will be received as status=0 why is this happening?
Last time I checked you need the ampersand. Try changing this:
@"username=%@ password=%@"
To this:
@"username=%@&password=%@"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.