Hi all,
I want to log on on the Exchange 2003 with form based authentication (FBA) via http-request (in objective-c).
Idea: 1)to connect with the code below and get 2 cookies from server. 2)to connect to server per WebDav with these cookies
There is the code for the first step. But instead of cookies I get the html-code for login-window for Exchange.
What is wrong?
Thank you so much!
NSString *authUrl=@"https://server/exchweb/bin/auth/owaauth.dll
NSString *loginPostString=@"destination=https://server/exchange/jack.black&flags=1&username=blackj&password=blablabla&SubmitCreds=Log+On&forcedownlevel=0&trusted=0";
NSData *loginPostData=[loginPostString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString* loginPostLength=[NSString stringWithFormat:@"%d", [loginPostData length]];
NSMutableURLRequest* loginRequest=[[[NSMutableURLRequest alloc]init]autorelease];
[loginRequest setHTTPShouldHandleCookies:YES];
[loginRequest setURL:[NSURL URLWithString:authUrl]];
[loginRequest setHTTPMethod:@"POST"];
[loginRequest setValue:loginPostLength forHTTPHeaderField:@"Content-Length"];
[loginRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-type"];
[loginRequest setHTTPBody: loginPostData];
NSError* loginError;
NSData* loginData;
NSHTTPURLResponse* loginResponse;
loginData=[NSURLConnection sendSynchronousRequest:loginRequest returningResponse:&loginResponse error:&loginError];
NSLog(@"status Code");
NSLog([NSHTTPURLResponse localizedStringForStatusCode:[loginResponse statusCode]]);
NSLog(@"loginResponse allHeaderFields %@",[loginResponse allHeaderFields]);
NSLog (@"%@", [[[NSString alloc] initWithData:loginData encoding:NSASCIIStringEncoding] autorelease]);