Sample code for 30+ languages & platforms
Visual FoxPro

Get the Server Certificate, Certificate Chain, and Root CA Certificate

See more HTTP Examples

Demonstrates how to get the HTTP server certificate, its certificate chain, and the root CA certificate.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loSslCert
LOCAL loCertChain
LOCAL loCert
LOCAL i
LOCAL lnNumCerts
LOCAL loCaCert

lnSuccess = 0

* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loHttp = CreateObject('Chilkat.Http')

* We're getting the SSL/TLS certificate, so make sure to connect to the SSL/TLS port (443).
loSslCert = CreateObject('Chilkat.Cert')
lnSuccess = loHttp.GetServerCert("apple.com",443,loSslCert)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loSslCert
    CANCEL
ENDIF

loCertChain = CreateObject('Chilkat.CertChain')
lnSuccess = loSslCert.BuildCertChain(loCertChain)
IF (lnSuccess = 0) THEN
    ? loSslCert.LastErrorText
    RELEASE loHttp
    RELEASE loSslCert
    RELEASE loCertChain
    CANCEL
ENDIF

loCert = CreateObject('Chilkat.Cert')
i = 0
lnNumCerts = loCertChain.NumCerts
DO WHILE i < lnNumCerts
    loCertChain.CertAt(i,loCert)
    ? "SubjectDN " + STR(i) + ": " + loCert.SubjectDN
    ? "IssuerDN " + STR(i) + ": " + loCert.IssuerDN
    i = i + 1
ENDDO

* If the certificate chain reaches the root CA cert, then the last cert in the chain
* is the root CA cert.
IF (loCertChain.ReachesRoot = 1) THEN
    loCaCert = CreateObject('Chilkat.Cert')
    loCertChain.CertAt(lnNumCerts - 1,loCaCert)
    ? "CA Root Cert: " + loCaCert.SubjectDN
ENDIF

RELEASE loHttp
RELEASE loSslCert
RELEASE loCertChain
RELEASE loCert
RELEASE loCaCert