我想使用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