Chilkat.HttpResponse Class Overview

Chilkat.HttpResponse represents an HTTP response returned by certain Chilkat.Http methods. It provides access to the response status line, status code, headers, cookies, charset, content length, body bytes, body text, full MIME response, redirect URL, and helper methods for saving or loading the body into Chilkat objects such as BinData, StringBuilder, JsonObject, JsonArray, and Xml.

What the Class Is Used For

Use Chilkat.HttpResponse to inspect and consume an HTTP response produced by the Chilkat.Http class. It is an output/result object: applications do not use it to send a request. Instead, it is returned by, or populated by, certain Http methods. In some APIs, the response/result object is passed as an output-only final argument, often named something like httpResult.

Important: HttpResponse is only used by Chilkat.Http as the output of some methods. It is a response-inspection and body-consumption object, not a standalone HTTP client.
Read Status Information Use StatusCode, StatusLine, and StatusText to determine the HTTP result.
Access Response Headers Read the full header, enumerate header fields, or get a specific header or header attribute.
Consume the Body Access the body as bytes, text, quoted-printable, full MIME, or load it into Chilkat data objects.
Read Cookies and Redirects Inspect response cookies and retrieve the final redirect URL for 301/302 responses.

Typical Workflow

  1. Use Chilkat.Http to send an HTTP request.
  2. Receive or populate a HttpResponse object from the Http method.
  3. Check StatusCode and StatusText to determine whether the server returned success, redirect, client error, or server error.
  4. Inspect headers with Header, GetHeaderField, or the indexed header methods.
  5. Check Charset and content-related headers before treating the body as text.
  6. Consume the body using the best method for the expected content: Body, BodyStr, GetBodyJson, GetBodyJarr, GetBodyXml, GetBodyBd, or SaveBodyBinary.
  7. Use LastErrorText after failures or unexpected behavior.

Core Concepts

Concept Meaning Important Members
Response Object A structured representation of an HTTP response produced by Chilkat.Http. StatusCode, Header, Body
Status Line The first line of the HTTP response, such as HTTP/1.0 200 OK. StatusLine, StatusCode, StatusText
Response Headers Header fields returned by the server, available as raw text or through indexed/name-based accessors. Header, NumHeaderFields, GetHeaderField
Response Body The payload returned by the server, available as bytes, text, encoded text, file output, or loaded into Chilkat data objects. Body, BodyStr, GetBodyBd, SaveBodyBinary
Cookies Cookies returned in the response can be inspected by index. NumCookies, GetCookieName, GetCookieValue

Status and Response Metadata

Property Purpose Example / Guidance
StatusLine The first line of the HTTP response. Example: HTTP/1.0 200 OK.
StatusCode Integer HTTP status code parsed from the response status line. For HTTP/1.0 200 OK, this returns 200.
StatusText Text following the status code in the response status line. For HTTP/1.0 200 OK, this returns OK.
Domain Domain of the HTTP server that created the response. Useful when following redirects or working with multiple servers.
DateStr Value of the Date response header in RFC822 date/time string format. Use when the server response date matters.
ContentLength Content length of the response body in bytes. Useful for diagnostics or deciding whether a body is too large for in-memory handling.
Charset Response charset, when applicable. Text responses may have a charset such as iso-8859-1. Binary images such as GIF or JPG typically do not.
FinalRedirectUrl Redirect URL for 301/302 responses. Inspect when the response is a redirect.

Header Access

Need Member Behavior
Get full header text Header Returns the full text of the HTTP response header.
Count headers NumHeaderFields Returns the number of response header fields.
Get header by name GetHeaderField Returns the value of a response header field by field name.
Get header attribute GetHeaderFieldAttr Returns an attribute from a header field. For example, response charset can be obtained as GetHeaderFieldAttr("content-type", "charset").
Enumerate header names GetHeaderName Gets the Nth response header field name. Indexing begins at 0.
Enumerate header values GetHeaderValue Gets the Nth response header field value. Indexing begins at 0.

Body Access Properties

Property Body Form Best Use
Body Byte array Use when the response is binary or when exact bytes are needed.
BodyStr String Use for text responses.
BodyQP Quoted-printable encoded string Use when the response body bytes should be represented as quoted-printable text.
FullMime Header + body Returns the full MIME form of the HTTP response, including both header and body.
Binary vs text: Use Body or SaveBodyBinary when exact bytes matter. Use BodyStr, GetBodySb, or text-specific loaders only when the response is known to be text.

Body Conversion and Loading Methods

Method Target Object Use When
GetBodyBd BinData Copy the response body bytes to a BinData object.
GetBodySb StringBuilder Copy the response body to a Chilkat StringBuilder.
GetBodyJson JsonObject Load the body into a JsonObject when the body is known to contain a JSON object beginning with { and ending with }.
GetBodyJarr JsonArray Load the body into a JsonArray when the body is known to contain a JSON array beginning with [ and ending with ].
GetBodyXml Xml Load the response body into a Chilkat Xml object when the body is known to contain XML.
Large body option: Set UncommonOptions to TakeResponseBody when the GetBody* methods should transfer the body to the target object instead of copying it. This can reduce memory usage for extremely large responses.

Saving the Response Body

Method Purpose Line Ending Behavior
SaveBodyBinary Saves the response body to a file exactly as binary data. No text or line-ending conversion. Use when exact bytes are required.
SaveBodyText Saves the response body to a text file. If bCrlf is true, line endings are converted to CRLF if necessary. If false, line endings are converted to bare LF if necessary.
Exact save rule: To save the response body exactly as-is, call SaveBodyBinary, not SaveBodyText.

Cookie Access

Need Member Behavior
Count cookies NumCookies Returns the number of cookies included in the response.
Get cookie name GetCookieName Returns the name of the Nth cookie. Indexing begins at 0.
Get cookie value GetCookieValue Returns the value of the Nth cookie.
Get cookie domain GetCookieDomain Returns the domain of the Nth cookie.
Get cookie path GetCookiePath Returns the path of the Nth cookie.
Get cookie expiration GetCookieExpiresStr Returns the expiration date/time of the Nth cookie.

Utility Methods

Method Purpose Example Use
UrlEncParamValue Parses a parameter value out of a URL-encoded parameter string. Given oauth_token=ABC&oauth_token_secret=123&oauth_callback_confirmed=true, requesting oauth_token_secret returns 123.

Uncommon Options

Option Introduced Behavior When Useful
TakeResponseBody v9.5.0.89 The GetBody* methods transfer the body to the target object instead of copying it. Useful for extremely large response bodies because it can reduce overall memory requirements.
Format: UncommonOptions can be set to a comma-separated list of special keywords. It should normally remain empty unless a documented option is needed.

Method Summary by Category

Category Methods / Properties Purpose
Status and metadata StatusLine, StatusCode, StatusText, Domain, DateStr, ContentLength, Charset, FinalRedirectUrl Inspect server response status, source, date, size, charset, and redirect destination.
Headers Header, NumHeaderFields, GetHeaderField, GetHeaderFieldAttr, GetHeaderName, GetHeaderValue Read, enumerate, and inspect response header fields and attributes.
Body access Body, BodyStr, BodyQP, FullMime, GetBodyBd, GetBodySb Access the response body as bytes, text, encoded text, full MIME, or Chilkat data containers.
Structured body loading GetBodyJson, GetBodyJarr, GetBodyXml Load response bodies directly into JSON object, JSON array, or XML objects when the body format is known.
Saving body SaveBodyBinary, SaveBodyText Save the response body to disk as exact binary data or text with controlled line endings.
Cookies NumCookies, GetCookieName, GetCookieValue, GetCookieDomain, GetCookiePath, GetCookieExpiresStr Enumerate cookies returned in the response.

Diagnostics and Troubleshooting

Problem Area Member What to Check
No response is available from an async task LoadTaskResult A false return means the asynchronous HTTP request failed in a way that no HTTP response was received.
Unexpected HTTP result StatusCode, StatusLine, StatusText Inspect the status fields first to determine whether the server returned success, redirect, client error, or server error.
Need a particular response header GetHeaderField, GetHeaderFieldAttr Use name-based header access, or attribute access for values such as a charset inside Content-Type.
Body is JSON but parsing fails GetBodyJson, GetBodyJarr Use GetBodyJson only for JSON objects beginning with {. Use GetBodyJarr only for JSON arrays beginning with [.
Need exact downloaded bytes Body, GetBodyBd, SaveBodyBinary Use binary body access or binary save methods rather than text conversion methods.
Text file line endings are wrong SaveBodyText Choose bCrlf = true for CRLF output or bCrlf = false for bare-LF output.
Memory use is high with large response bodies UncommonOptions Consider TakeResponseBody so GetBody* transfers rather than copies the body.
Need diagnostic details after a failure LastErrorText Check diagnostic text after failed or unexpected response operations.

Common Pitfalls

Pitfall Better Approach
Treating HttpResponse as a request-sending object. Use Chilkat.Http to send requests. Use HttpResponse only to inspect the response.
Assuming a response exists when an async HTTP request fails. Use LoadTaskResult and check its return value. A failed return can mean no HTTP response was received.
Using BodyStr for binary content. Use Body, GetBodyBd, or SaveBodyBinary for binary responses.
Calling GetBodyJson for a JSON array. Use GetBodyJarr when the response body is a JSON array.
Calling GetBodyJarr for a JSON object. Use GetBodyJson when the response body is a JSON object.
Saving exact binary data with SaveBodyText. Use SaveBodyBinary to preserve the response body exactly as-is.
Ignoring StatusCode before parsing the body. Check the HTTP status first, then parse or save the body according to the server response.

Best Practices

Recommendation Reason
Check StatusCode before processing the body. The server may return an error or redirect body instead of the expected content.
Use the body accessor that matches the expected content. Binary, text, JSON object, JSON array, XML, and file-save workflows each have dedicated members.
Use SaveBodyBinary for exact file output. It avoids line-ending conversion and preserves the response bytes.
Use GetHeaderFieldAttr for header parameters. It is convenient for values such as charset within Content-Type.
Use indexed methods when enumerating headers or cookies. Indexing begins at 0 and is bounded by NumHeaderFields or NumCookies.
Use TakeResponseBody for unusually large response bodies. It can reduce memory requirements by transferring the body to the target object rather than copying it.
Check LastErrorText after failures. It provides useful diagnostic detail for body loading, body saving, async response loading, header access, cookie access, and parsing issues.

Summary

Chilkat.HttpResponse is the Chilkat response object produced by certain Chilkat.Http methods. It is used to inspect the status line, status code, response headers, cookies, charset, content length, redirects, and response body. The body can be accessed as bytes, text, quoted-printable, full MIME, JSON, XML, BinData, StringBuilder, or saved directly to disk.

The most important practical guidance is to remember that HttpResponse is an output/result object from Chilkat.Http, check the status code first, choose the correct body accessor for the response type, use binary methods when exact bytes matter, and inspect LastErrorText when response handling fails.