NTLM 和 Kerberos 身份验证

默认 NTLM 身份验证和 Kerberos 身份验证使用与调用应用程序关联的 Microsoft Windows 用户凭据来尝试通过服务器进行身份验证。 使用非默认 NTLM 身份验证时,应用程序会将认证类型设置为 NTLM,并使用 NetworkCredential 对象将用户名、密码和域传递给主机,如下例所示。

Dim myUri As String = "http://www.contoso.com/"  
Using handler As New HttpClientHandler()
    With handler
        .Credentials = New NetworkCredential(UserName, SecurelyStoredPassword, Domain)
    End With
    Using client As New HttpClient(handler)
        Dim result As String = Await client.GetStringAsync(myUri)
        ' Do Other Stuff...
    End Using
End Using
string myUri = "http://www.contoso.com/";
using HttpClientHandler handler = new()
{
    Credentials = new NetworkCredential(UserName, SecurelyStoredPassword, Domain),
};
using HttpClient client = new(handler);
string result = await client.GetStringAsync(myUri);
// Do Other Stuff...

需要使用应用程序用户凭据连接到 Internet 服务的应用程序可以使用用户默认凭据进行此操作,如以下示例所示。

Dim myUri As String = "http://www.contoso.com/"  
Using handler As New HttpClientHandler()
    With handler
        .Credentials = CredentialCache.DefaultCredentials
    End With
    Using client As New HttpClient(handler)
        Dim result As String = Await client.GetStringAsync(myUri)
        ' Do Other Stuff...
    End Using
End Using 
string myUri = "http://www.contoso.com/";
using HttpClientHandler handler = new()
{
    Credentials = CredentialCache.DefaultCredentials,
};
using HttpClient client = new(handler);
string result = await client.GetStringAsync(myUri);
// Do Other Stuff...

协商身份验证模块确定远程服务器使用 NTLM 身份验证还是 Kerberos 身份验证,并发送相应响应。

备注

无法通过代理服务器进行 NTLM 身份验证。

请参阅