NSURLConnection with HTTPS

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

  1. macrumors member

    Feb 24, 2004
    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?

  2. macrumors 6502a


    Jan 4, 2002
    Austin, TX
    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:

    -(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
        if ([MTUserName length] > 0) { // MTUserName is whatever login credentials you have
            NSURLCredential *newCredential;
            newCredential=[NSURLCredential credentialWithUser:MTUserName	
            [[challenge sender] useCredential:newCredential
        } else {
            [[challenge sender] cancelAuthenticationChallenge:challenge];
            // inform the user that the user name and password
            // in the preferences are incorrect
            [self showPreferencesCredentialsAreIncorrectPanel:self];
  3. thread starter macrumors member

    Feb 24, 2004
    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