Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

TurboLag

macrumors member
Original poster
Feb 24, 2004
85
0
I am trying to scrape a webpage which requires authentication. I have implemented the required delegate methods for NSURLConnection, but didReceiveAuthenticationChallenge is not hit. I am trying to scrape: https://www.rogers.com/web/myrogers/internetUsage?actionTab=DayToDay

Should my initial request be to this page, or should I first reach the logon page? And, is there some boiler template for sending the username and password once the authentication challenge is hit?

Thanks.
 
What you should do is construct a request that simulates the login form if a user were to click on SUBMIT. Look at the source and find the action and the names of the form elements (sometimes there are hidden values). Make up a URL that points to the action with the proper form elements as parameters and start there.

Then you can use something like this:

Code:
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{

    if ([MTUserName length] > 0) { // MTUserName is whatever login credentials you have
        NSURLCredential *newCredential;
        newCredential=[NSURLCredential credentialWithUser:MTUserName	
                                                 password:MTPassWord	
                                              persistence:NSURLCredentialPersistenceNone];
        [[challenge sender] useCredential:newCredential
               forAuthenticationChallenge:challenge];
    } else {
        [[challenge sender] cancelAuthenticationChallenge:challenge];
        // inform the user that the user name and password
        // in the preferences are incorrect
        [self showPreferencesCredentialsAreIncorrectPanel:self];
    }
}
 
Okay, so it seems I should be pointing to https://www.rogers.com/web/link/signin. Looking at the source of that page, the names of the forms are 'USER' and 'password'.

However, I still dont get a call to didGetAuthenticationChallenge. What is the criterion for this delegate method to be called?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.