解析受密码保护的HTML

时间:2012-05-16 05:54:24

标签: ios asiformdatarequest

我只想在登录后从页面中检索源(字符串)。当我按下登录按钮时,它会给我第一页的源(登录页面)。无论我输入正确还是错误的密码,结果都一样。非常感谢您的帮助。

` - (IBAction)buttonPressed:(id)sender {

// PERFORM LOGIN
url = [NSURL URLWithString:@"https://www.page asking username and password/"]; 
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setRequestMethod:@"POST"];
[request setPostValue:userName.text forKey:@"UserID"];
[request setPostValue:password.text forKey:@"Password"];
[request setDelegate:self];

[request setDidFailSelector:@selector(PostFailed:)];
[request setDidFinishSelector:@selector(PostFinished:)];
[request startSynchronous];

}

- (void)PostFailed:(ASIHTTPRequest *)theRequest
{
//notify user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error sending request to the server" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];


}

- (void)PostFinished:(ASIHTTPRequest *)theRequest

{
    //到这里你的帖子回复数据...

// ATTEMPT TO ACCESS ACCOUNT SUMMARY DATA
url = [NSURL URLWithString:@"https://www.page after I loged in"]; 
ASIHTTPRequest *mainRequest = [ASIHTTPRequest requestWithURL:url]; 

[theRequest setDelegate:self];
[mainRequest startAsynchronous]; 


NSLog(@"Response %d ==> %@", theRequest.responseStatusCode, [theRequest responseString]);

} `

1 个答案:

答案 0 :(得分:0)

您尝试检索的网站很可能使用Cookies对您进行身份验证。 由于您正在进行原始HTTP请求而不是代表您存储cookie,因此您始终会被重定向到登录页面,因为您始终保持未经身份验证。

要访问更多网站,您必须在代码中实施Cookie处理。