0

我有一个使用 Windows 身份验证托管在 IIS 上的网站。我正在尝试在我的一个 iPhone Web 应用程序中访问它。目前我正在使用此代码,但它不起作用。

NSString *authString = [[[NSString stringWithFormat:@"%@:%@", @"myusername", @"mypassword"]dataUsingEncoding:NSUTF8StringEncoding] base64Encoding];

authString = [NSString stringWithFormat: @"Basic %@", authString];

**[requestObj setValue:authString forHTTPHeaderField:@"Authorization"];**

我的 Web 应用程序使用 Windows 身份验证托管。但在这里我使用的是基本的。任何人都可以发布什么是正确的 http 标头。

谢谢..

4

4 回答 4

4

我认为主要区别在于您需要指定您正在验证的域以及用户名和密码。像这样的东西应该工作。为简洁起见,我使用了同步请求,理想情况下,您应该使用 ASINetworkQueue 或 NSOperationQueue 来执行请求。

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]);
}

我无权访问 Windows 服务器来测试这个,但我过去测试过 NTLM,所以它应该可以工作...... :)

于 2009-05-08T12:03:57.667 回答
1

Windows 身份验证 (NTLM) 不像基本身份验证那么简单。NTLM 需要多个 web 请求来协商安全性,因此没有可以发送用于登录的静态 HTTP 标头。

于 2009-05-06T21:48:15.323 回答
0

您可以使用第三方ASIHTTPRequest 库来执行 NTLM over HTTP 身份验证。

于 2009-05-07T06:22:20.393 回答
0

我不是 100% 确定它支持 NTLM 身份验证,但你调查connection:didReceiveAuthenticationChallenge过 NSUrlConnection 上的方法吗?

于 2009-05-08T00:40:00.160 回答