Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 873773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:59:44+00:00 2026-05-15T10:59:44+00:00

Morning Everyone, I’ve been attempting to write an application that does some GETs from

  • 0

Morning Everyone,

I’ve been attempting to write an application that does some GETs from a remote Web Service that requires authentication. My main problem is that the majority of these remote servers (and there are a lot of them) don’t have valid certificates. I’ve got code to accept the invalid certificate and code to respond to the challenge with the correct uname & pass (below). The problem I’m having is getting the two to play together. I can’t seem to find a way to send the challenge both NSURLCredentials or a way to chain the callbacks correctly. When I try to chain them I can’t get my NSURLRequest to call didReceiveAuthenticationChallenge twice.

Any thoughts would be appreciated!

Code for Authentication…

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{   
    if(!hasCanceled){
        if ([challenge previousFailureCount] == 0) {
            NSURLCredential *newCredential;
            newCredential=[NSURLCredential credentialWithUser:_username password:_password persistence:NSURLCredentialPersistenceNone];
            [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
        } 
        else {
            [[challenge sender] cancelAuthenticationChallenge:challenge];
            NSLog(@"Bad Username Or Password");
            badUsernameAndPassword = YES;
            finished = YES;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:59:45+00:00Added an answer on May 15, 2026 at 10:59 am

    You can only reply to an NSURLAuthenticationChallenge with a credential for that challenge. You can determine what type of challenge you’ve received using:

    [[challenge protectionSpace] authenticationMethod]
    

    The possible values are documented here. In the case of an invalid server certificate, the authentication method will be NSURLAuthenticationMethodServerTrust. In your code, you should check the authentication method and respond appropriately.

    if ([challenge previousFailureCount] > 0) {
        // handle bad credentials here
        [[challenge sender] cancelAuthenticationChallenge:challenge];
        return;
    }
    
    if ([[challenge protectionSpace] authenticationMethod] == NSURLAuthenticationMethodServerTrust) {
        // check if the user has previously accepted the certificate, otherwise prompt
    } else if ([[challenge protectionSpace] authenticationMethod] == /* your supported authentication method here */) {
        [[challenge sender] useCredential:/* your user's credential */ forAuthenticationChallenge:challenge];
    }
    

    It’s not an error if you don’t get both authentication challenges each time. You can cache credentials when you create them. If you do, you won’t necessarily be prompted again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good morning, I am the developer of a medium sized PDA application that will
Good morning, I am working on a C# winform application that is using validation
Good morning everyone! I'm doing a distributed application using .NET 4.0, C# and Remoting
Morning all, hope everyone is ok. I have an ODS that uses a combination
Morning, So we've got a Magento installation that's been working fine for two months,
Morning all, I've created a custom control with an image property. That image property
This morning, I tried to commit a revision to Subversion and found that all
Morning Everyone!.. General Routing Quesiton Here... I'm currently working to achieve a route similar
Good morning everyone, I'm running into an issue using a SharePoint workflow project (C#,
Good Morning everyone, I am using an update command in php to update data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.