zoukankan      html  css  js  c++  java
  • (C#) HTTP Authentication (Basic, NTLM, Digest, Negotiate/Kerberos)

    演示如何使用HTTP身份验证。可以将身份验证添加到向服务器发送HTTP请求的任何方法,例如SynchronousRequest,QuickGetStr,PostXml等。要添加身份验证,只需设置“登录”和“密码”属性即可。

    默认情况下,Chilkat将使用基本的HTTP身份验证,该身份验证通过连接发送登录名/密码明文。如果不使用SSL / TLS(即HTTPS),这将很糟糕。但是,如果连接是安全的,则使用基本身份验证应该没有任何问题。

    Chilkat还支持更安全的身份验证类型,包括Digest,NTLM和Negotiate(可在NTLM和Kerberos之间动态选择)。要使用摘要式身份验证,只需将DigestAuth属性设置为true。要使用NTLM身份验证,请设置NtlmAuth属性= true。同样,要使用协商身份验证,请将NegotiateAuth属性设置为true。

    重要:只有Windows平台上运行的Chilkat实现才支持协商身份验证。这是因为它是使用Microsoft的SSPI API在内部实现的。但是,由于Chilkat直接实现NTLM(即不将Microsoft SSPI用于基础实现),因此NTLM身份验证可用于所有受支持的操作系统。

    Chilkat .NET Assemblies

    Chilkat for .NET Core

    Chilkat for Mono


    //
    This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Chilkat.Http http = new Chilkat.Http(); // Set the Login and Password properties for authentication. http.Login = "chilkat"; http.Password = "myPassword"; // To use HTTP Basic authentication.. http.BasicAuth = true; string html = http.QuickGetStr("http://localhost/xyz.html"); if (http.LastMethodSuccess != true) { Debug.WriteLine(http.LastErrorText); return; } // Examine the HTTP status code returned. // A status code of 401 is typically returned for "access denied" // if no login/password is provided, or if the credentials (login/password) // are incorrect. Debug.WriteLine("HTTP status code for Basic authentication: " + Convert.ToString(http.LastStatus)); // Examine the HTML returned for the URL: Debug.WriteLine(html); Chilkat.Http http2 = new Chilkat.Http(); // To use NTLM authentication, set the // NtlmAuth property = true http2.NtlmAuth = true; // The session log can be captured to a file by // setting the SessionLogFilename property: http2.SessionLogFilename = "ntlmAuthLog.txt"; // Examination of the HTTP session log will show the NTLM // back-and-forth exchange between the client and server. // This call will now use NTLM authentication (assuming it // is supported by the web server). html = http2.QuickGetStr("http://localhost/xyz.html"); // Note: if (http2.LastMethodSuccess != true) { Debug.WriteLine(http2.LastErrorText); return; } Debug.WriteLine("HTTP status code for NTLM authentication: " + Convert.ToString(http2.LastStatus)); Chilkat.Http http3 = new Chilkat.Http(); // To use Digest Authentication, set the DigestAuth property = true // Also, no more than one of the authentication type properties // (NtlmAuth, DigestAuth, and NegotiateAuth) should be set // to true. http3.DigestAuth = true; http3.SessionLogFilename = "digestAuthLog.txt"; // This call will now use Digest authentication (assuming it // is supported by the web server). html = http3.QuickGetStr("http://localhost/xyz.html"); if (http3.LastMethodSuccess != true) { Debug.WriteLine(http3.LastErrorText); return; } Debug.WriteLine("HTTP status code for Digest authentication: " + Convert.ToString(http3.LastStatus));
  • 相关阅读:
    Linq-分页查询
    思维导图软件xmind和mindmanager哪个更好
    Enterprise Architect使用教程
    敏捷开发之Scrum
    总结---4
    判断单链表是否存在环
    设计模式分类
    实用手册:130+ 提高开发效率的 vim 常用命令
    Reverse Linked List II
    Single Number and Single Number II
  • 原文地址:https://www.cnblogs.com/xuxml/p/14777425.html
Copyright © 2011-2022 走看看