Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) Debugging HTTPThe 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.
#include <CkHttp.h> void ChilkatSample(void) { CkString strOut; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttp http; // 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. const char *html = 0; 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.) SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.