HTTP Authentication Headers for Windows IIS Authentication
I have a website hosted in IIS with Windows Authentication. I am trying to access it in one of my iPhone applications. I am currently using this code, but it doesn't work.
NSString * authString = [[[NSString stringWithFormat: @ "% @:% @", @ "myusername", @ "mypassword"] dataUsingEncoding: NSUTF8StringEncoding] base64Encoding];
authString = [NSString stringWithFormat: @"Basic %@", authString];
**[requestObj setValue:authString forHTTPHeaderField:@"Authorization"];**
my web app is hosted with windows authentication. but here I am using basic. can anyone post what is the correct http header for it.
Thanks..
a source to share
I think the main difference is that you need to provide the domain that you are authenticating with, as well as the username and password. Something like this should work. I used a synchronous request for brevity, ideally you should use an ASINetworkQueue or NSOperationQueue to make the request.
NSString *username = @"test";
NSString *password = @"test";
NSString *domain = @"test";
NSURL *url = [NSURL URLWithString:@"http://myurl"];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[request setUseSessionPersistence:YES];
[request setUsername:username];
[request setPassword:password];
[request setDomain:domain];
[request start];
if ([request error]) {
if ([[request error] code] == ASIAuthenticationErrorType) {
//Authentication failed
}
} else {
NSLog([request responseString]);
}
I don't have access to a windows server to test this, but I've tested NTLM in the past, so it should work ... :)
a source to share
You can use the third party ASIHTTPRequest library to perform NTLM authentication over HTTP.
a source to share