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 に答える