0

I'm trying to access a website using my login credentials through an iPhone app but the NSLog just shows the site with the login screen...I need the one AFTER the login screen. My code is as follows:

- (IBAction)buttonClicked:(id)sender
{
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://webportal.factorforms.com/Portal/Form_Login.aspx"]];

    [request setPostValue:[self.usernameField text] forKey:@"Login1$UserName"];
    [request setPostValue:[self.passwordField text] forKey:@"Login1$Password"];

    [request setDelegate:self];
    [request startAsynchronous];
}

- (void)requestFailed:(ASIHTTPRequest *)request {
    NSLog(@"Request failed: %@",[request error]);
}

- (void)requestFinished:(ASIHTTPRequest *)request {
    NSLog(@"Submitted form successfully");
    NSLog(@"Response was:");
    NSLog(@"%@",[request responseString]);
}

My response is just the log in screen....I thought I would be getting the javascript for my actual login. I'm not sure what I'm doing wrong.

beryllium
  • 29,669
  • 15
  • 106
  • 125
fmi
  • 512
  • 4
  • 14
  • Not sure if my question is clear. I'm expecting the resulting data to show the screen after I have logged in, but instead I'm getting my original url that houses the login/password fields – fmi Nov 03 '11 at 18:16

2 Answers2

0

May be your website after login has multiple redirections? You must parse it too. ASIHttp can do it. [Just opinion.]

Didikot
  • 66
  • 1
0

I've run into similar problems when trying to communicate with .NET sites, and doing the following worked for me:

  1. including a post value for the submit button itself, like

    [request setPostValue:@"Login" forKey:@"Login1$LoginButton"];

  2. including a post value for the page's viewstate since I think this can be validated in some setups:

    NSString *viewState = @"/wEPDwUKMjE0MjI5NDA3Ng9kFgICBA9kFgYCAQ9kFgQCAQ88KwAKAQAPFgIeCFVzZXJOYW1lZWRkAgcPFgIeB1Zpc2libGVoZAIDDxYCHwFoZAIFDxYCHgNzcmMFFkxvZ2luRnJhbWUvRkFDVE9SLmFzcHhkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBRdMb2dpbjEkTG9naW5JbWFnZUJ1dHRvbitnh1yDOsbCwQpF6Ic5hi0OUJ4q";

    [request setPostValue:viewState forKey:@"__VIEWSTATE"];

  3. include a post value for the page's event validation, since I think this can be validated in some setups:

    NSString *eventValidation = @"/wEWBQL9m8PyDQKUvNa1DwL666vYDAKnz4ybCAKI7MDFB3FJcnRzxnTY+gW6x83FqZF+QS+6";

    [request setPostValue:eventValidation forKey:@"__EVENTVALIDATION";

From memory, I threw all three of these at the problem and my login then succeeded, but I should really have spent the time figuring out if all three were required.

Warren
  • 61
  • 2