我正在尝试通过自动登录到该网站来在 UIWebView 中加载网站。我正在发布用户名和密码。它加载网站但未登录。登录不起作用。任何想法?
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];