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
(C#) 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.
// This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Chilkat.Http http = new Chilkat.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.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. string html; 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.