我想使用NSMutableURLRequest自动登录到ASP.NET网站。我正在发送所有可以想到的帖子参数,并且与其他网站的效果很好。 (如基于WordPress的)。但我无法让它为ASP.net网站工作。有人可以向我解释我该如何解决这个问题?Objective C - 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]:http://stackoverflow.com/questions/1973325/nsurlconnection-and-basic- http认证 – 2013-10-14 06:12:37