目标c:点击网站按钮编程

Objective-C: Click Website Button Programmatically

本文关键字:网站 按钮 编程 目标      更新时间:2023-09-26

如何通过Objective-C编程地按下网站上的按钮?目前,我向网站发送一个HTTP帖子并检索返回的NSData:

NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"https://grades.bsd405.org/Pinnacle/Gradebook/Logon.aspx?ReturnUrl=%2fPinnacle%2fGradebook%2fInternetViewer%2fGradeSummary.aspx"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
//[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[request setTimeoutInterval:20];
[NSURLConnection connectionWithRequest:request delegate:self];

发送HTTP post返回正确的NSData,但每隔几周服务器更新HTTP post属性,如viewStateeventValidation。这可以防止我硬编码这些值。是否有任何方法发送一个新闻与用户名和密码使用Javascript网站,或动态输入viewStateeventValidation参数?以下是我试图实现此过程的网站:https://grades.bsd405.org/Pinnacle/Gradebook/Logon.aspx?ReturnUrl=%2fPinnacle%2fGradebook%2fDefault.aspx

您可以编写webservice来获取服务器更新的HTTP post属性,如viewState和eventValidation。一旦你有了这些最新的属性,你就可以在最终的web请求中发布了。