HttpResponse Chilkat2 Perl Reference Documentation

Chilkat2::HttpResponse

Current Version: 11.7.0

Markdown version of this page for AI tools (v 11.7.0) · all AI docs

Chilkat.HttpResponse

Inspect HTTP status, headers, cookies, redirects, and response bodies.

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 response body into Chilkat objects such as BinData, StringBuilder, JsonObject, JsonArray, and Xml.

Status and reason

Read the HTTP status code, status line, and related response information to determine whether the request succeeded, redirected, or failed.

Headers and cookies

Inspect response headers, retrieve individual header values, and access cookies returned by the server.

Body as text or bytes

Get the response body as raw bytes or decoded text, using the response charset information when appropriate.

Structured body loading

Load the body directly into JsonObject, JsonArray, Xml, BinData, or StringBuilder objects for further processing.

Redirect information

Access redirect-related information such as the redirect URL when the server responds with a redirect status.

Save and inspect responses

Save body content, inspect the full MIME-style response, and use response metadata for diagnostics, logging, or API troubleshooting.

Common pattern: Send a request with Chilkat.Http, check the StatusCode, inspect headers or cookies as needed, then retrieve the body in the form best suited to the response content: text, bytes, BinData, StringBuilder, JSON, or XML. Use HttpResponse for response inspection; use Chilkat.Http for the actual network request.

Object Creation

use Chilkat2;

my $httpResponse = Chilkat2::HttpResponse->new;
# or set properties (and RaiseError) at creation:
# my $httpResponse = Chilkat2::HttpResponse->new(VerboseLogging => 1, RaiseError => 1);
my $httpResponse = Chilkat2::HttpResponse->new(Property => $value, ...);

Creates the object. The optional pairs set writable properties (and RaiseError) in order, as if set one by one; an unknown or read-only name croaks. use Chilkat2; loads every class; the Chilkat2/HttpResponse.pm file holds only this class's documentation (perldoc Chilkat2::HttpResponse).

Perl frees the object when its last reference goes (undef $httpResponse, or the variable going out of scope); there is nothing to close. Objects returned by methods are independent and freed the same way. The class may be subclassed (use parent -norequire, 'Chilkat2::HttpResponse';): an object is a blessed hash reference whose hash is free for the subclass's own fields.

my $boolVal = $httpResponse->RaiseError;
$httpResponse->RaiseError($boolVal);

When false (the default), a method that fails returns false (or undef), and the reason is in LastErrorText. When true, it dies with a Chilkat2::Error instead, as DBI does with its RaiseError. Objects returned by a method inherit the value of the object that returned them.

Errors

A Chilkat2::Error stringifies to the failed call's full LastErrorText, and has the methods text, class ('Chilkat2::HttpResponse'), method (the method name) and object. Methods that look something up and find nothing return undef without dying (each such method says so), methods that answer a question (HasMember, IsUnlocked, ...) return a plain boolean, and property reads and writes never fail for Chilkat reasons.

Misuse always croaks, with your file and line, whatever RaiseError is: a wrong number of arguments, a reference or undef where a string or number is expected, an object of the wrong class, an out-of-range integer, a string containing a NUL character, a wide character in a byte string, or a write to a read-only property.

Strings are Perl character strings in both directions (length, regexes and :encoding layers see characters); binary data (BinData) is a byte string. Unlocking: call Chilkat2::Global->new->UnlockBundle('...') once at startup.

Properties

BodyQP
# $strVal is a string (read-only)
my $strVal = $httpResponse->BodyQP;

The same as the Body property, but returned as a quoted-printable encoded string.

top
BodyStr
# $strVal is a string (read-only)
my $strVal = $httpResponse->BodyStr;

The response body returned as a string.

top
Charset
# $strVal is a string (read-only)
my $strVal = $httpResponse->Charset;

The response charset, such as iso-8859-1, if applicable. Obviously, responses for GIF and JPG files will not have a charset.

top
ContentLength
# $intVal is an integer (read-only)
my $intVal = $httpResponse->ContentLength;

The content length of the response, in bytes.

top
ContentLength64
# $intVal is an integer (read-only)
my $intVal = $httpResponse->ContentLength64;

The content length of the response, in number of bytes, returned as a 64-bit integer.

top
DateStr
# $strVal is a string (read-only)
my $strVal = $httpResponse->DateStr;

Returns the content of the Date response header field in RFC822 date/time string format.

top
DebugLogFilePath
# $strVal is a string
my $strVal = $httpResponse->DebugLogFilePath;
$httpResponse->DebugLogFilePath($strVal);

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
Domain
# $strVal is a string (read-only)
my $strVal = $httpResponse->Domain;

The domain of the HTTP server that created this response.

top
FinalRedirectUrl
# $strVal is a string (read-only)
my $strVal = $httpResponse->FinalRedirectUrl;
Introduced in version 9.5.0.49

Returns the redirect URL for 301/302 responses.

top
FullMime
# $strVal is a string (read-only)
my $strVal = $httpResponse->FullMime;

Returns the full MIME (header + body) of the HTTP response.

top
Header
# $strVal is a string (read-only)
my $strVal = $httpResponse->Header;

The full text of the response header.

top
LastErrorHtml
# $strVal is a string (read-only)
my $strVal = $httpResponse->LastErrorHtml;

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
# $strVal is a string (read-only)
my $strVal = $httpResponse->LastErrorText;

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
# $strVal is a string (read-only)
my $strVal = $httpResponse->LastErrorXml;

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
# $boolVal is a boolean
my $boolVal = $httpResponse->LastMethodSuccess;
$httpResponse->LastMethodSuccess($boolVal);

Indicates the success or failure of the most recent method call: 1 means success, 0 means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
NumCookies
# $intVal is an integer (read-only)
my $intVal = $httpResponse->NumCookies;

The number of cookies included in the response.

top
NumHeaderFields
# $intVal is an integer (read-only)
my $intVal = $httpResponse->NumHeaderFields;

The number of response header fields.

top
StatusCode
# $intVal is an integer (read-only)
my $intVal = $httpResponse->StatusCode;

The status code (as an integer) from the first line of an HTTP response. If the StatusLine = HTTP/1.0 200 OK, the response status code returned is 200.

top
StatusLine
# $strVal is a string (read-only)
my $strVal = $httpResponse->StatusLine;

The first line of an HTTP response, such as HTTP/1.0 200 OK.

top
StatusText
# $strVal is a string (read-only)
my $strVal = $httpResponse->StatusText;
Introduced in version 9.5.0.49

The text that follows the status code in the 1st line of the HTTP response. For example, i the first line of an HTTP response is HTTP/1.0 200 OK, then this property contains OK.

top
UncommonOptions
# $strVal is a string
my $strVal = $httpResponse->UncommonOptions;
$httpResponse->UncommonOptions($strVal);
Introduced in version 9.5.0.89

This is a catch-all property to be used for uncommon needs. Can be set to a list of the following comma separated keywords:

  • TakeResponseBody - Introduced in v9.5.0.89. The GetBody* methods will transfer the body to the target object instead of copying the contents. This can be useful if the response body is extremely large because it will reduce the overall memory requirement.

top
VerboseLogging
# $boolVal is a boolean
my $boolVal = $httpResponse->VerboseLogging;
$httpResponse->VerboseLogging($boolVal);

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
# $strVal is a string (read-only)
my $strVal = $httpResponse->Version;

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

GetBodyBd
# $binData is a Chilkat2::BinData
# $success is true or false
my $success = $httpResponse->GetBodyBd($binData);
Introduced in version 9.5.0.64

Copies the response body to a BinData object.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

More Information and Examples
top
GetBodyJarr
# $jarr is a Chilkat2::JsonArray
# $success is true or false
my $success = $httpResponse->GetBodyJarr($jarr);
Introduced in version 9.5.0.89

Loads the JSON array response body into a JsonArray This method should only be called when it is known that the response body contains a JSON array (beginning with a square bracket '[' and ending with a square bracket ']')

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

More Information and Examples
top
GetBodyJson
# $json is a Chilkat2::JsonObject
# $success is true or false
my $success = $httpResponse->GetBodyJson($json);
Introduced in version 9.5.0.89

Loads the JSON response body into a JsonObject. This method should only be called when it is known that the response body contains JSON (beginning with a curly brace '{' and ending with a curly brace '}')

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

More Information and Examples
top
GetBodySb
# $sb is a Chilkat2::StringBuilder
# $success is true or false
my $success = $httpResponse->GetBodySb($sb);
Introduced in version 9.5.0.64

Copies the response body to a Chilkat StringBuilder object.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
GetBodyXml
# $xml is a Chilkat2::Xml
# $success is true or false
my $success = $httpResponse->GetBodyXml($xml);
Introduced in version 9.5.0.89

Loads the XML response body into an XML object. This method should only be called when it is known that the response body contains XML.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

More Information and Examples
top
GetCookieDomain
# $index is an integer
# $str is a string or undef
my $str = $httpResponse->GetCookieDomain($index);

Returns the domain of the Nth cookie in the response. Indexing begins at 0. The number of response cookies is specified in the NumCookies property.

Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
GetCookieExpiresStr
# $index is an integer
# $str is a string or undef
my $str = $httpResponse->GetCookieExpiresStr($index);

Returns the expiration date/time of the Nth cookie in the response. Indexing begins at 0. The number of response cookies is specified in the NumCookies property.

Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
GetCookieName
# $index is an integer
# $str is a string or undef
my $str = $httpResponse->GetCookieName($index);

Returns the name of the Nth cookie returned in the response. Indexing begins at 0. The number of response cookies is specified in the NumCookies property.

Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
GetCookiePath
# $index is an integer
# $str is a string or undef
my $str = $httpResponse->GetCookiePath($index);

Returns the path of the Nth cookie returned in the response. Indexing begins at 0. The number of response cookies is specified in the NumCookies property.

Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
GetCookieValue
# $index is an integer
# $str is a string or undef
my $str = $httpResponse->GetCookieValue($index);

Returns the value of the Nth cookie returned in the response. Indexing begins at 0. The number of response cookies is specified in the NumCookies property.

Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
GetHeaderField
# $fieldName is a string
# $str is a string or undef
my $str = $httpResponse->GetHeaderField($fieldName);

Returns the value of a response header field accessed by field name.

Returns undef if not found: this is not an error, and it never dies, whatever RaiseError is.

top
GetHeaderFieldAttr
# $fieldName is a string
# $attrName is a string
# $str is a string or undef
my $str = $httpResponse->GetHeaderFieldAttr($fieldName, $attrName);

Returns a response header field attribute. As an example, the response charset is simply the GetHeaderFieldAttr(content-type,charset)

Returns undef if not found: this is not an error, and it never dies, whatever RaiseError is.

top
GetHeaderName
# $index is an integer
# $str is a string or undef
my $str = $httpResponse->GetHeaderName($index);

Gets the name of the Nth response header field. Indexing begins at 0. The number of response headers is specified by the NumHeaderFields property.

Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
GetHeaderValue
# $index is an integer
# $str is a string or undef
my $str = $httpResponse->GetHeaderValue($index);

Gets the value of the Nth response header field. Indexing begins at 0. The number of response headers is specified by the NumHeaderFields property.

Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
SaveBodyBinary
# $path is a string
# $success is true or false
my $success = $httpResponse->SaveBodyBinary($path);

Saves the body of the HTTP response to a file.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
SaveBodyText
# $bCrlf is a boolean
# $path is a string
# $success is true or false
my $success = $httpResponse->SaveBodyText($bCrlf, $path);

Saves the HTTP response body to a file. This method provides control over CRLF vs bare-LF line-endings. If $bCrlf is 1, then line endings are automatically converted to CRLF if necessary. If $bCrlf is 0, then line-endings are automatically converted to bare-LF's (Unix style) if necessary.

To save the HTTP response body exactly as-is (with no line-ending manipulation), then call SaveBodyBinary.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
UrlEncParamValue
# $encodedParamString is a string
# $paramName is a string
# $str is a string or undef
my $str = $httpResponse->UrlEncParamValue($encodedParamString, $paramName);

Convenience method for parsing a param's value out of a URL-encoded param string. For example, if a caller passes the following string in $encodedParamString:

oauth_token=ABC&oauth_token_secret=123&oauth_callback_confirmed=true
and oauth_token_secret in $paramName, then the return value would be 123.

Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top