Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Lianja) REST through SSH TunnelDemonstrates how to connect through an SSH Tunnel (via port-forwarding) to make REST API calls.
// This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loTunnel = createobject("CkSocket") lcSshHostname = "sftp.example.com" lnSshPort = 22 // Connect to an SSH server and establish the SSH tunnel: llSuccess = loTunnel.SshOpenTunnel(lcSshHostname,lnSshPort) if (llSuccess <> .T.) then ? loTunnel.LastErrorText release loTunnel return endif // Authenticate with the SSH server via a login/password // or with a public key. // This example demonstrates SSH password authentication. llSuccess = loTunnel.SshAuthenticatePw("mySshLogin","mySshPassword") if (llSuccess <> .T.) then ? loTunnel.LastErrorText release loTunnel return endif // OK, the SSH tunnel is setup. Now open a channel within the tunnel. // (Any number of channels may be created from the same SSH tunnel. // Multiple channels may coexist at the same time.) // This example connects to a REST server through the SSH tunnel. // It will connect to the Amazon AWS service for this example. loRest = createobject("CkRest") llBTls = .T. lnPort = 443 lnMaxWaitMs = 5000 // This returns a socket object that is a single channel within the SSH tunnel. loChannel = loTunnel.SshOpenChannel("s3.amazonaws.com",lnPort,llBTls,lnMaxWaitMs) if (loTunnel.LastMethodSuccess <> .T.) then ? loTunnel.LastErrorText release loTunnel release loRest return endif // Use the connection. (This connection is a TLS running on an SSH channel through an SSH tunnel. // In other words, TLS is wrapped within the SSH tunnel.) llSuccess = loRest.UseConnection(loChannel,.T.) if (llSuccess <> .T.) then ? loRest.LastErrorText release loChannel release loTunnel release loRest return endif // Provide AWS credentials for the REST call. loAuthAws = createobject("CkAuthAws") loAuthAws.AccessKey = "AWS_ACCESS_KEY" loAuthAws.SecretKey = "AWS_SECRET_KEY" loAuthAws.ServiceName = "s3" llSuccess = loRest.SetAuthAws(loAuthAws) // List all buckets for the account... lcResponseXml = loRest.FullRequestNoBody("GET","/") if (loRest.LastMethodSuccess <> .T.) then ? loRest.LastErrorText release loChannel release loTunnel release loRest release loAuthAws return endif loXml = createobject("CkXml") llSuccess = loXml.LoadXml(lcResponseXml) // Show the full XML returned. ? loXml.GetXml() // Iterate over the buckets, showing each bucket name. llSuccess = loXml.FindChild2("Buckets") if (loXml.FirstChild2() = .T.) then ? loXml.GetChildContent("Name") do while (loXml.NextSibling2() = .T.) ? loXml.GetChildContent("Name") enddo endif // Move the internal pointer back to the root node. loXml.GetRoot2() release loChannel release loTunnel release loRest release loAuthAws release loXml |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.