jeudi 5 mars 2015

Post Method in IPhone programming for logining in to the application

I am trying to Post the email and password in my iphone application but i dont know with out entering any data in to the text fields also it says connection Succesfull



- (IBAction)enterButtonAction:(id)sender
{
NSString *post =[NSString stringWithFormat:@"user[email]=%@&user[password]=%@",[userNameTF text],[passWordTF text]];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:@"http://ift.tt/17NCfTJ"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
// [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection * connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];


if (connection) {
NSLog(@"Connection Successfull");
} else {
NSLog(@"Connection UnSuccessfull");
}
}



Aucun commentaire:

Enregistrer un commentaire