0

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

`- (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]);

} `

4

1 回答 1

0

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

要访问更多站点,您必须在代码中实现 cookie 处理。

于 2012-05-16T06:13:08.167 回答