Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Ruby Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Ruby) Debugging HTTP

The 1st step in debugging a failed HTTP request (or determining the reason for an unexpected response) is to get more information about what actually happened. The Chilkat HTTP component/class have properties that provide this information. The most useful is the SessionLogFilename property. It may be set to a filepath that is to be created or appended by the HTTP component. The exact HTTP requests and responses are logged to this file. The session log file can be examined to verify that the HTTP request(s) sent to the web server contain the expected data and are structurally formatted as expected.

The standard LastErrorText / LastErrorXml / LastErrorHtml properties can also provide information about what transpired. These properties are standard to all Chilkat components/classes, and contain information about what transpired (for a given object instance) for the very last method called. Regardless of the success or failure status returned by the method, the LastErrorText will always contain information. The VerboseLogging property may be set to true to get more detailed information in LastErrorText. (It is best to first examine the LastErrorText without VerboseLogging, and then only use VerboseLogging if necessary.)

Other properties exist to provide less detailed, but more succinct and easily accessible information, such as LastHeader, LastStatus, WasRedirected, LastContentType, etc.

Important: The SessionLogFilename, LastErrorText, and other debugging related properties apply to ALL Chilkat HTTP methods that communicate with an HTTP server.

Chilkat Ruby Downloads

install from rubygems.org

gem install chilkat

or download... Ruby Library for Windows, MacOS, Linux, Alpine Linux

require 'chilkat'

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

http = Chilkat::CkHttp.new()

# This example demonstrates session logging via the
# SessionLogFilename property.  It also examines the 
# contents of the LastErrorText and a few other properties
# to see what transpired in a seemingly simple HTTP GET request.

http.put_SessionLogFilename("/temp/httpSessionLog.txt")

# The "http://www.paypal.com" URL was chosen on
# purpose to demonstrate the potential complexity
# of a seemingly simple HTTP GET request and response.
# 
# In this case, the initial response is a 301 redirect to
# "https://www.paypal.com/" because all communication
# with PayPal must be over SSL/TLS.  The Chilkat HTTP
# FollowRedirects property defaults to true, causing the
# redirect to be followed automatically.  
# The request is resent using SSL/TLS and the response
# received is a complex one:  it is both Gzipped (compressed)
# and "chunked".  Internally, Chilkat automatically handles
# the decompression and the re-composing of the chunked
# response to return the simple HTML page that is the result.

html = http.quickGetStr("http://www.paypal.com/")

# Looking at the httpSessionLog, we can see the initial
# HTTP request, the 301 response, the subsequent 
# HTTP GET request to follow the redirect, and the final
# gzipped/chunked response:

# ---- Sending ----
# GET / HTTP/1.1
# Accept: */*
# Accept-Encoding: gzip
# Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
# Accept-Language: en-us,en;q=0.5
# Host: www.paypal.com
# Connection: Keep-Alive
# 
# 
# ---- Received ----
# HTTP/1.1 301 Moved Permanently
# Date: Sat, 25 Jun 2011 14:50:36 GMT
# Server: Apache
# Set-Cookie: cwrClyrK4LoCV1fydGbAxiNL6iG..; domain=.paypal.com; path=/; HttpOnly
# Set-Cookie: cookie_check=yes; expires=Tue, 22-Jun-2021 14:50:37 GMT; domain=.paypal.com; path=/; HttpOnly
# Location: https://www.paypal.com/
# Vary: Accept-Encoding
# Content-Encoding: gzip
# Keep-Alive: timeout=5, max=100
# Connection: Keep-Alive
# Transfer-Encoding: chunked
# Content-Type: text/html
# 
# 10
# (10 bytes of binary (non-printable) data here...)
# 
# ---- Sending ----
# GET / HTTP/1.1
# Accept: */*
# Accept-Encoding: gzip
# Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
# Accept-Language: en-us,en;q=0.5
# Host: www.paypal.com
# Connection: Keep-Alive
# 
# 
# ---- Received ----
# HTTP/1.1 200 OK
# Date: Sat, 25 Jun 2011 14:50:37 GMT
# Server: Apache
# Cache-Control: private
# Pragma: no-cache
# Expires: Thu, 05 Jan 1995 22:00:00 GMT
# Set-Cookie: cwrClyrK4DoCV1fydGbAxiNL6iG=jE8s ...; domain=.paypal.com; path=/; Secure; HttpOnly
# Set-Cookie: KHcl0EuY7AKSMgfvHl7J5E7hPtK=YSG ...; expires=Fri, 20-Jun-2031 14:50:38 GMT; 
#  domain=.paypal.com; path=/; Secure; HttpOnly
# Set-Cookie: cookie_check=yes; expires=Tue, 22-Jun-2021 14:50:38 GMT; domain=.paypal.com; path=/; 
#  Secure; HttpOnly
# Set-Cookie: navcmd=_home-general; domain=.paypal.com; path=/; Secure; HttpOnly
# Set-Cookie: consumer_display=USER_HOMEPAGE...;
#  expires=Tue, 22-Jun-2021 14:50:38 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
# Set-Cookie: navlns=0.0; expires=Fri, 20-Jun-2031 14:50:38 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
# Set-Cookie: Apache=10.73.8.36.1309013437867506; path=/; expires=Mon, 17-Jun-41 14:50:37 GMT
# Vary: Accept-Encoding
# Content-Encoding: gzip
# Strict-Transport-Security: max-age=500
# Keep-Alive: timeout=5, max=100
# Connection: Keep-Alive
# Transfer-Encoding: chunked
# Content-Type: text/html; charset=UTF-8
# 
# 1895
# (The remainder of the HTTP response is binary data.)

 

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