Objective-C:以编程方式单击网站按钮

时间:2014-05-26 05:46:35

标签: javascript ios objective-c xcode web

如何通过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帖子会返回正确的NSData,但每隔几周服务器就会更新HTTP帖子属性,例如viewStateeventValidation。这可以防止我对这些值进行硬编码。有没有办法使用Javascript使用用户名和密码向网站发送新闻,或动态输入viewStateeventValidation参数?以下是我尝试为https://grades.bsd405.org/Pinnacle/Gradebook/Logon.aspx?ReturnUrl=%2fPinnacle%2fGradebook%2fDefault.aspx

实施此流程的网站

1 个答案:

答案 0 :(得分:0)

您可以编写Web服务来获取服务器更新的HTTP post属性,例如viewState和eventValidation。 获得这些最新属性后,您可以在最终的Web请求中发布。