【发布时间】:2023-03-23 11:10:01
【问题描述】:
我正在尝试使用 NSMutableURLRequest 自动登录到 ASP.NET 网站。我正在发送我能想到的所有帖子参数,并且它适用于其他网站。 (例如,基于 Wordpress)。但我无法让它为 ASP.net 网站工作。有人可以向我解释一下我该如何解决这个问题吗?
NSString *post = @"__LASTFOCUS=&__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUJNjM4NDU2MzY5ZGT%2F7rz73weImm5JbYQQ4q2lRY3HUw%3D%3D&__EVENTVALIDATION=%2FwEWBQK9gI6LAwKY4eTfDQKmw8%2B%2FAQLerrfAAwKQxuCGAT0xfZqPEPwFCfa5fbrvTZXDSnbY&ctl00%24SideBarContent%24UserName=demo&ctl00%24SideBarContent%24Password=demo&ctl00%24SideBarContent%24LoginButton=Login&ctl00%24SideBarContent%24UserTimeZoneCrawler%24offset=02%3A00%2C0";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *postRequest = [[NSMutableURLRequest alloc] init];
[postRequest setURL:[NSURL URLWithString:@"http://asp.net/website/logon.aspx"]];
[postRequest setHTTPMethod:@"POST"];
[postRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[postRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[postRequest setHTTPBody:postData];
[postRequest setValue:@"loginCookie=UserName=demo; SessionContext=ydnwyyz5n50mt2zjn3yiarq0" forHTTPHeaderField:@"Cookie"];
问候, EZFrag
【问题讨论】:
-
检查 [NSURLConnection 和基本 HTTP 身份验证][1] [1]: stackoverflow.com/questions/1973325/…
标签: asp.net objective-c authentication