Basic HTTP Authentication in iOS while calling webservice


– (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {

    if ([challenge previousFailureCount] == 0) {

        NSLog(@”received authentication challenge”);

        NSURLCredential *newCredential = [NSURLCredentialcredentialWithUser:@”tylerhorne”

                                                                    password:@”m2n1shlko”

                                                                 persistence:NSURLCredentialPersistenceForSession];

        NSLog(@”credential created”);

        [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];

        NSLog(@”responded to authentication challenge”);

    }

    else {

        NSLog(@”previous authentication failure”);

    }

}

Advertisements

One thought on “Basic HTTP Authentication in iOS while calling webservice

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: