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
Read the HTTP status code, status line, and related response information
to determine whether the request succeeded, redirected, or failed.
Inspect response headers, retrieve individual header values, and access
cookies returned by the server.
Get the response body as raw bytes or decoded text, using the response
charset information when appropriate.
Load the body directly into
Access redirect-related information such as the redirect URL when the
server responds with a redirect status.
Save body content, inspect the full MIME-style response, and use response
metadata for diagnostics, logging, or API troubleshooting.
For an extended overview, see
HttpResponse Class Overview.
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
Headers and cookies
Body as text or bytes
Structured body loading
JsonObject,
JsonArray, Xml, BinData, or
StringBuilder objects for further processing.
Redirect information
Save and inspect responses
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);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.
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
my $strVal = $httpResponse->BodyQP;
The same as the Body property, but returned as a quoted-printable encoded string.
topBodyStr
my $strVal = $httpResponse->BodyStr;
The response body returned as a string.
topCharset
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.
ContentLength
my $intVal = $httpResponse->ContentLength;
The content length of the response, in bytes.
topContentLength64
my $intVal = $httpResponse->ContentLength64;
The content length of the response, in number of bytes, returned as a 64-bit integer.
topDateStr
my $strVal = $httpResponse->DateStr;
Returns the content of the Date response header field in RFC822 date/time string format.
topDebugLogFilePath
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.
Domain
my $strVal = $httpResponse->Domain;
The domain of the HTTP server that created this response.
topFinalRedirectUrl
my $strVal = $httpResponse->FinalRedirectUrl;
Returns the redirect URL for 301/302 responses.
topFullMime
my $strVal = $httpResponse->FullMime;
Header
my $strVal = $httpResponse->Header;
The full text of the response header.
topLastErrorHtml
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.
topLastErrorText
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.
LastErrorXml
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.
topLastMethodSuccess
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.
NumCookies
my $intVal = $httpResponse->NumCookies;
The number of cookies included in the response.
topNumHeaderFields
my $intVal = $httpResponse->NumHeaderFields;
The number of response header fields.
topStatusCode
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.
StatusLine
my $strVal = $httpResponse->StatusLine;
The first line of an HTTP response, such as HTTP/1.0 200 OK.
StatusText
my $strVal = $httpResponse->StatusText;
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.
UncommonOptions
my $strVal = $httpResponse->UncommonOptions;
$httpResponse->UncommonOptions($strVal);
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.
VerboseLogging
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.
Version
my $strVal = $httpResponse->Version;
Methods
GetBodyBd
# $success is true or false
my $success = $httpResponse->GetBodyBd($binData);
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.
GetBodyJarr
# $success is true or false
my $success = $httpResponse->GetBodyJarr($jarr);
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.
GetBodyJson
# $success is true or false
my $success = $httpResponse->GetBodyJson($json);
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.
GetBodySb
# $success is true or false
my $success = $httpResponse->GetBodySb($sb);
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.
GetBodyXml
# $success is true or false
my $success = $httpResponse->GetBodyXml($xml);
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.
GetCookieDomain
# $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.
GetCookieExpiresStr
# $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.
GetCookieName
# $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.
GetCookiePath
# $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.
GetCookieValue
# $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.
GetHeaderField
# $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.
GetHeaderFieldAttr
# $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.
GetHeaderName
# $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.
GetHeaderValue
# $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.
SaveBodyBinary
# $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.
SaveBodyText
# $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.
UrlEncParamValue
# $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=trueand
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.