Hi,
I'm trying to connect to a server that requires HTTP authentication and that lives on a non-standard port. I've written a little bit of code that works great when it tries to connect to a server on port 80, but I get an error when connecting to the non-standard port, and I get it without it trying to connect at all:

{
    NSErrorFailingURLKey = http://192.168.0.5:42334/;
    NSErrorFailingURLStringKey = "http://192.168.0.5:42334/";;
NSUnderlyingError = Error Domain=kCFErrorDomainCFNetwork Code=-1012 UserInfo=0x1f0b40 "Operation could not be completed. (kCFErrorDomainCFNetwork error -1012.)";
}


Here is my code:

+ (void) test {
        NSString *host = @"http://192.168.0.5:42334/";;
        NSString *username = @"someuser";
        NSString *password = @"somepass";
        int port = 42334;
        
NSURLCredential *newCredential =[NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceForSession]; NSURLProtectionSpace *space = [[NSURLProtectionSpace alloc] initWithHost:host port:port protocol:@"http" realm:nil authenticationMethod:nil];
        
NSURLCredentialStorage *store = [NSURLCredentialStorage sharedCredentialStorage];
        [store setCredential:newCredential forProtectionSpace:space];
        
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:host] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:30];

        NSURLResponse *response;
        NSError *error;
NSData *returnData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];

        if(error) {
                NSLog(@"test error: %@", error);
                NSLog(@"test userinfo: %@", [error userInfo]);
        } else {
                NSLog(@"test response: %@", response);
                NSLog(@"test result: %d", returnData);
        }
}

What am I doing wrong? How should I modify the code to connect correctly? Also, do I need to do anything specific if I want to support servers that require NTLM or Digest authentication rather than Basic? Where can I look up errorcode -1012?

Cheers

   Nik
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to