Re: Connecting to non-standard HTTP ports with authorization
Re: Connecting to non-standard HTTP ports with authorization
- Subject: Re: Connecting to non-standard HTTP ports with authorization
- From: Niklas Saers <email@hidden>
- Date: Mon, 30 Jun 2008 15:10:37 +0200
Just a little update,
-1012 is NSURLErrorUserCancelledAuthentication, and that caught my
suspicioun that perhaps data got sent anyway. So fire up Wireshark,
and sure enough, my request is sent:
GET /Pages/Default.aspx HTTP/1.1
User-Agent: (myApp/0.1 (myApp)
Accept: */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: 192.168.0.5:42334
And a 401 is passed back, with NTLM authentication, not Basic. Sorry
about that, but it doesn't really change anything with my problem as
far as I know:
HTTP/1.1 401 Unauthorized
Content-Length: 1656
Content-Type: text/html
Server: Microsoft-IIS/6.0
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
MicrosoftSharePointTeamServices: 12.0.0.4518
X-Powered-By: ASP.NET
Date: Mon, 30 Jun 2008 12:55:40 GMT
And then of course it fails again, and the -1012 is returned saying
the user cancled while in fact, no authentication info was sent. So my
question is: how can I make a correct NTLM authentication via HTTP,
because what I'm doing right now seems to be incorrect
Cheers
Nik
On Jun 30, 2008, at 11:54 AM, Niklas Saers wrote:
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:
This email sent to email@hidden