(JavaScript) Debugging HTTP
To debug a failed HTTP request or an unexpected response, start by gathering more information about the event.
The Chilkat Http class provides several properties to assist in this process.
The most valuable is the SessionLogFilename property, which you can set to a file path where the Http object will log the complete requests and responses.
Reviewing this log helps ensure the requests sent to the server are correctly formatted and contain the expected data.
Additionally, the standard LastErrorText, LastErrorXml, and LastErrorHtml properties offer insights into what occurred during the last method call for a given object instance.
These properties record details regardless of the method's success or failure status.
Setting the VerboseLogging property to true provides more detailed information in LastErrorText, but it's recommended to review LastErrorText without VerboseLogging first and enable it only if necessary.
There are other properties for quick and accessible details, such as LastHeader, LastStatus, WasRedirected, LastContentType, and more.
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var http = new CkHttp();
// 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.SessionLogFilename = "c:/temp/qa_output/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 302 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.
var html;
html = http.QuickGetStr("http://www.paypal.com/");
// Looking at the httpSessionLog, we can see the initial
// HTTP request, the 302 response, the subsequent
// HTTP GET request to follow the redirect, and the final
// gzipped/chunked response:
// ---- Sending Wed, 20 Aug 2025 11:10:12 GMT ----
// GET / HTTP/1.1
// Host: www.paypal.com
// Accept: */*
// Accept-Encoding: gzip
//
//
// ---- Received Wed, 20 Aug 2025 11:10:12 GMT ----
// HTTP/1.1 302 Found
// Connection: close
// Content-Length: 0
// Server: Varnish
// Retry-After: 0
// Location: https://www.paypal.com/us/home
// Accept-Ranges: bytes
// Date: Wed, 20 Aug 2025 11:10:13 GMT
// Via: 1.1 varnish
// X-Served-By: cache-chi-klot8100033-CHI
// X-Cache: HIT
// X-Cache-Hits: 0
// Server-Timing: content-encoding;desc="",x-cdn;desc="fastly"
//
//
// ---- Sending Wed, 20 Aug 2025 11:10:12 GMT ----
// GET /us/home HTTP/1.1
// Host: www.paypal.com
// Accept: */*
// Accept-Encoding: gzip
//
//
// ---- Received Wed, 20 Aug 2025 11:10:12 GMT ----
// HTTP/1.1 200 OK
// Connection: keep-alive
// x-content-type-options: nosniff
// cache-control: max-age=0, no-cache, no-store, must-revalidate
// timing-allow-origin: *
// ...
// ...
// content-encoding: gzip
// ...
// ...
// transfer-encoding: chunked
//
// 2ef4
// ...
// ...
// ...
|