Parsing password protected HTML

263 views Asked by At

I just want to retrieve the source (string) from the page after I logged in. When I push login button it gives me the source of the first page (login page). The result is the same whether I put correct or wrong password. Your help would be much appreciated.

`- (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

{
//get here your post response data...

// 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

There are 1 answers

1
0x90 On BEST ANSWER

Most likely the site you are trying to retrieve authenticates you using Cookies. Since you are making raw HTTP requests and not cookie is stored on your behalf, you are always redirected to the login page as you always remain unauthenticated.

To access further sites you will have to implement cookie handling in your code.