Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicPythonRubySQL ServerSwiftTclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcel

Android™ Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Bounced Email
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GeoOp
Google APIs
Google Cloud Storage
Google Drive
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc

IMAP
JSON
Java KeyStore (JKS)
Jwt
MHT / HTML Email
MIME
NTLM
OAuth1
OAuth2
OpenSSL
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
Socket/SSL/TLS
Spider
Stream
Tar Archive
Twitter
XML
XMP
Xero
Zip
curl

 

 

 

(Android™) HTTP Authentication (Basic, NTLM, Digest, Negotiate/Kerberos)

Demonstrates how to use HTTP authentication. Authentication can be added to any method that sends an HTTP request to the server, such as SynchronousRequest, QuickGetStr, PostXml, etc. To add authentication, simply set the Login and Password properties.

By default, Chilkat will use basic HTTP authentication, which sends the login/password clear-text over the connection. This is bad if SSL/TLS (i.e. HTTPS) is not used. However, if the connection is secure, there should be nothing wrong with using basic authentication.

Chilkat supports more secure authentication types as well, including Digest, NTLM, and Negotiate (which dynamically chooses between NTLM and Kerberos). To use Digest authentication, simply set the DigestAuth property = true. To use NTLM authentication, set the NtlmAuth property = true. Likewise, to use Negotiate authentication, set the NegotiateAuth property = true.

Important: Negotiate authentication is only supported for the Chilkat implementations that run on the Windows platform. This is because it is implemented internally using Microsoft's SSPI API. NTLM authentication however, is available for all supported operating systems because Chilkat implements NTLM directlly (i.e. does not use Microsoft SSPI for the underlying implementation.)

Chilkat Android™ Downloads

Android™ Java Libraries

Android C/C++ Libraries

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    CkHttp http = new CkHttp();

    boolean success;

    //  Any string unlocks the component for the 1st 30-days.
    success = http.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        Log.i(TAG, http.lastErrorText());
        return;
    }

    //  Set the Login and Password properties for authentication.
    http.put_Login("chilkat");
    http.put_Password("myPassword");

    String html = http.quickGetStr("http://localhost/xyz.html");
    //  Note:
    if (http.get_LastMethodSuccess() != true) {
        Log.i(TAG, 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.
    Log.i(TAG, "HTTP status code for Basic authentication: " + String.valueOf(http.get_LastStatus()));

    //  Examine the HTML returned for the URL:
    Log.i(TAG, html);

    CkHttp http2 = new CkHttp();

    //  To use NTLM authentication, set the
    //  NtlmAuth property = true
    http2.put_NtlmAuth(true);

    //  The session log can be captured to a file by
    //  setting the SessionLogFilename property:
    http2.put_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.get_LastMethodSuccess() != true) {
        Log.i(TAG, http2.lastErrorText());
        return;
    }

    Log.i(TAG, "HTTP status code for NTLM authentication: " + String.valueOf(http2.get_LastStatus()));

    CkHttp http3 = new CkHttp();

    //  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.put_DigestAuth(true);

    http3.put_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");
    //  Note:
    if (http3.get_LastMethodSuccess() != true) {
        Log.i(TAG, http3.lastErrorText());
        return;
    }

    Log.i(TAG, "HTTP status code for Digest authentication: " + String.valueOf(http3.get_LastStatus()));

  }

  static {
      // Important: Make sure the name passed to loadLibrary matches the shared library
      // found in your project's libs/armeabi directory.
      //  for "libchilkat.so", pass "chilkat" to loadLibrary
      //  for "libchilkatemail.so", pass "chilkatemail" to loadLibrary
      //  etc.
      // 
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

 

© 2000-2016 Chilkat Software, Inc. All Rights Reserved.