I’m trying to load a website in UIWebView by automatically login to that website. I’m posting username and password . It loads the website but not logged in. The login not working. any idea?
NSURL *url = [NSURL URLWithString:@"http://www.abc.com"];
NSString *post = [NSString stringWithFormat:@"login_name=%@&login_password=%@&submit=Login", @"abc", @"abc"];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"POST Length = %@",postLength);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[request setTimeoutInterval:5.0];
[webView loadRequest:request];
I just built a sample app with my code to load a webview. I call a specific page in my form submission and it works to login to the web service. I am posting the code here:
Maybe this code will help you.