NSURLConnection with HTTPS

Discussion in 'Mac Programming' started by TurboLag, Oct 12, 2009.

  1. TurboLag
    Expand Collapse
    macrumors member

    Joined:
    Feb 24, 2004
    #1
    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.
     
  2. Sayer
    Expand Collapse
    macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #2
    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];
        }
    }
     
  3. TurboLag
    Expand Collapse
    thread starter macrumors member

    Joined:
    Feb 24, 2004
    #3
    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?
     

Share This Page