Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Connecting to non-standard HTTP ports with authorization



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 (email@hidden)

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/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.