Note: This class is not available with the PO_NO_NETWORK parse option.
The HTTPClient class can be used to communicate with HTTP servers using the HTTP or HTTPS (HTTP using an SSL/TLS encrypted connection) protocol.
By default 'Connection: Keep-Alive' is always sent regardless of the HTTP protocol level set for the object, however if a server response contains 'Connection: close', the connection will be closed as soon as the full response (including any message body if present) has been read.
HTTP redirect responses are supported and can be limited with the max_redirects constructor hash key or by using the HTTPClient::setMaxRedirects() method. The default number of redirects is 5.
HTTP basic authentication is supported; set the username and password in the URL (ex: http://username:password@host:port/path). To change the URL from the one set by the constructor, call HTTPClient::setURL().
HTTP proxies and basic proxy authentication are supported by setting the proxy constructor hash key to the proxy URL (with a proxy username and password if required) or by calling the HTTPClient::setProxyURL() method.
Objects of this class are thread-safe and support serializing multiple simultaneous requests from many threads. If a request is in progress and another thread attempts to make a request at the same time, the second thread will block until the first is complete. Therefore the total amount of time a thread could wait for a response in a multi-threaded context could be greater than the read timeout value.
This class understands and automatically decodes "deflate", "gzip", and "bzip2" content encodings as well.
The default read timeout value is 300,000 milliseconds (5 minutes). Note that the read timeout value applies to individual packets; for this reason for large transfers the overall read time could exceed the read timeout value.
When an exception is thrown (for example, a response code of < 200 or >= 400 is received from the server), any message body returned will be in the "arg" key of the exception hash.
This class understands the protocols in the following table.
Table 4.415. HTTPClient Class Protocols
Protocol | Default Port | SSL? | Description |
|---|---|---|---|
| 80 | No | Unencrypted HTTP protocol |
| 443 | Yes | HTTP protocol with SSL/TLS encryption |
Whenever using an HTTPClient method where a hash of headers can be passed to the method, some headers are generated by default by the class and can be overridden, and some are cannot be overridden and are ignored if passed by the client. See the following tables for details.
Table 4.416. HTTPClient Mandatory Headers
Header | Description |
|---|---|
| This header is only sent if a message body is send, and, if so, the length is calculated automatically. |
Table 4.417. HTTPClient Default, but Overridable Headers
Header | Default Value |
|---|---|
|
|
|
|
|
|
|
|
|
|
This class supports posting network events to a Queue. See Event Handling for more information.
The events raised by this object are listed in the following table:
Table 4.418. HTTPClient Events
Name | Description |
|---|---|
Raised when the HTTP "Content-Length" header is received. | |
Raised when HTTP chunked data is about to be received. | |
Raised when all HTTP chunked data has been received. | |
Raised when an HTTP redirect message is received. | |
Raised when an HTTP message is sent. | |
Raised when an HTTP message is received. | |
Raised when HTTP footers are received. | |
Raised when a block of HTTP chunked data is received. | |
Raised when the next chunk size for HTTP chunked data is known. |
The following table gives an overview of the methods available in the HTTPClient class.
Table 4.419. HTTPClient Class Method Overview
|
Method |
Except? |
Description |
|---|---|---|
|
|
Y |
Creates the HTTPClient object based on the parameters passed. |
|
N |
Destroys the HTTPClient object and closes any open connections. | |
Y | Copying objects of this class is not supported, an exception will be thrown. | |
|
| N | Returns the current URL. |
|
| Y | Sets a new URL value for the next connection. |
|
| N | Returns the current proxy URL as a string or NOTHING if no proxy URL is set. |
|
| Y | Sets or clears (in case called with no argument) a new proxy URL value for the next connection. |
|
| N | Clears the proxy URL value. |
|
| N | Sets the SSL/TLS flag for the next connection to the proxy. |
|
| N | Returns the SSL/TLS flag. |
|
| N | Returns the current |
|
| N | Updates the |
|
|
N |
Connects to the remote socket; SSL/TLS negotiation is performed if required. |
|
|
N |
Disconnects from the remote socket |
|
|
Y |
Sends an HTTP GET request and returns the message body received as a string or NOTHING if no message body is received. In order to get the headers and the body, use the HTTPClient::send() method instead. If no connection is established, an internal call to HTTPClient::connect() will be made before sending the message. |
|
|
Y |
Sends an HTTP HEAD request and returns as hash of the headers received. If no connection is established, an internal call to HTTPClient::connect() will be made before sending the message. |
|
|
Y |
Sends an HTTP POST request with a message body and returns the message body received as a string or NOTHING if no message body is received. In order to get the headers and the body in the response, use the HTTPClient::send() method instead. If no connection is established, an internal call to HTTPClient::connect() will be made before sending the message. |
|
|
Y |
Sends an HTTP request with the specified method and optional message body and returns headers and any body received as a response in a hash format. If no connection is established, an internal call to HTTPClient::connect() will be made before sending the message. |
|
| N | Sets the connect timeout in milliseconds. Negative numbers mean use the default system connect timeout. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. |
|
| N | Sets the default read timeout in milliseconds. Zero means immediate timeout (will return data only if it is already available), and negative numbers mean never timeout (wait forever for data). Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. |
|
| N | Returns the connect timeout as an integer in milliseconds. Negative numbers mean the system default timeout is used. |
|
| N | Returns the default read timeout as an integer in milliseconds. Zero means immediate timeout (only returns data if it is already available), and negative numbers mean never timeout (wait forever for data). |
|
|
Y |
Sets the HTTP protocol version string for headers in outgoing messages, allowed values are '1.0' and '1.1'. |
|
|
N |
Returns the HTTP protocol version string used in outgoing messages. |
|
|
N |
Sets the object to make a secure SSL/TLS connection on the next connect if the passed argument is |
|
|
N |
Returns |
|
|
N |
Returns a string code giving the result of verifying the remote certificate or NOTHING if a secure connection is not established. Return value are the keys described in the X509_VerificationReasons hash constant. This hash can also be used to generate a textual description of the verification result. |
|
|
N |
Returns the name of the cipher as a string for an encrypted connection or NOTHING if a secure connection is not established. |
|
|
N |
Returns the version of the cipher as a string for an encrypted connection or NOTHING if a secure connection is not established. |
|
|
Y |
Sets the string encoding for the object; any strings deserialized with this object will be tagged with this character encoding. |
|
| N | Returns the character encoding used for the object |
|
| N | Sets a Queue object to receive HTTPClient and Socket events or clears the queue if no argument is passed. |
|
| N | Returns the |
|
| N | Sets the |
|
| N | Returns |
Creates the HTTPClient object based on the parameters passed. To connect, call any method that requires a connection and an implicit connection is established, or call HTTPClient::connect().
HTTPClient::constructor(hash $opts)
my HTTPClient $httpclient(("url":"http://hostname:8080/path"));
Table 4.420. Arguments for HTTPClient::constructor()
|
Argument |
Description |
|---|---|
|
|
sets options and changes default behaviour for the object, etc. See the table below for information on valid keys and their mening. Note that the key names are case-sensitive and therefore must all be in lower-case. |
Table 4.421. HTTPClient::constructor() Option Hash Keys
Key | Description |
|---|---|
| A string giving the URL to connect to. |
| The default port number to connect to if none is given in the URL. |
| A hash describing new protocols, the key is the protocol name and the value is either an integer giving the default port number or a hash with 'port' and 'ssl' keys giving the default port number and a boolean value to indicate that an SSL connection should be established. |
| Either '1.0' or '1.1' for the claimed HTTP protocol version compliancy in outgoing message headers. |
| The default path to use for new connections if a path is not otherwise specified in the connection URL. |
| The maximum number of redirects before throwing an exception (the default is 5). |
| The proxy URL for connecting through a proxy. |
| The timeout value in milliseconds (also can be a relative date-time value for clarity, ex: |
| The timeout value in milliseconds for establishing a new socket connection (also can be a relative date-time value for clarity, ex: |
Table 4.422. Exceptions thrown by HTTPClient::constructor()
err | desc |
|---|---|
| invalid or unknown option passed in option hash |
| invalid URL string |
| unknown protocol passed in URL |
Destroys the HTTPClient object and closes any open connections.
delete $httpclient;
Copying objects of this class is not supported, an exception will be thrown.
Table 4.423. Exceptions thrown by HTTPClient::copy()
|
err |
desc |
|---|---|
|
|
objects of this class may not be copied |
Returns the current URL value for the object. To set the URL, use the HTTPClient::setURL() method.
HTTPClient::getURL() returns string
$url = $httpclient.getURL();
Sets the URL value for the object. To retrieve the current URL value, use the HTTPClient::getURL() method.
HTTPClient::setURL(string $url) returns nothing
$httpclient.setURL("https://user:password@hostname:8080/path");
Table 4.425. Arguments for HTTPClient::setURL()
Argument | Description |
|---|---|
| The new URL for the object. |
Table 4.426. Exceptions thrown by HTTPClient::setURL()
err | desc |
|---|---|
| invalid URL string |
| unknown protocol passed in URL |
Returns the current proxy URL value for the object (NOTHING if no proxy URL is set). To set the proxy URL, use the HTTPClient::setProxyURL() method.
HTTPClient::getProxyURL() returns any
$proxy_url = $httpclient.getProxyURL();
Sets the proxy URL value for the object; call with no argument or NOTHING to clear. To retrieve the current URL value, use the HTTPClient::getProxyURL() method.
HTTPClient::setProxyURL() returns nothing
HTTPClient::setProxyURL(string $url) returns nothing
$httpclient.setProxyURL("http://user:password@proxy_host:8080/path");
Table 4.429. Exceptions thrown by HTTPClient::setProxyURL()
err | desc |
|---|---|
| invalid URL string |
| invalid authorization credentials in proxy URL (username without password or vice-versa) |
| unknown protocol passed in URL |
Clears the current proxy URL
HTTPClient::clearProxyURL() returns nothing
$httpclient.clearProxyURL();
Sets the SSL/TLS flag for the next proxy connection. To check the flag, use the HTTPClient::isProxySecure() method.
HTTPClient::setProxySecure(softbool $secure = True) returns nothing
$httpclient.setProxySecure(True);
Table 4.430. Arguments for HTTPClient::setProxySecure()
Argument | Description |
|---|---|
| sets the SSL/TLS flag for the next proxy connection |
Returns the SSL/TLS flag for proxy connection. To set the flag, use the HTTPClient::setProxySecure() method.
HTTPClient::isProxySecure() returns bool
$bool = $httpclient.isProxySecure();
Table 4.431. Return Values for HTTPClient::isProxySecure()
Return Type | Description |
|---|---|
The value of the SSL/TLS flag for the proxy connection. |
Returns the maximum number of redirects allowed for the object. To set this value, use the HTTPClient::setMaxRedirects() method.
HTTPClient::getMaxRedirects() returns int
$num = $httpclient.getMaxRedirects();
Table 4.432. Return Values for HTTPClient::getMaxRedirects()
Return Type | Description |
|---|---|
The current value of the |
Sets the maximum number of redirects allowed for the object. To retrieve this value, use the HTTPClient::getMaxRedirects() method.
HTTPClient::setMaxRedirects(softint $max = 0) returns nothing
$httpclient.setMaxRedirects(0); # disable redirections
Table 4.433. Arguments for HTTPClient::setMaxRedirects()
Argument | Description |
|---|---|
| The maximum number of HTTP redirects allowed for the object before an exception is thrown. |
Connects to the remote socket. If the protocol indicates that a secure connection should be established (or HTTPClient::setSecure() was called previsouly), SSL/TLS negotiation will be attempted. Note: For possible exceptions, see the Socket::connect() method (or Socket::connectSSL() for secure connections).
If the TCP_NODELAY flag has been set (see HTTPClient::setNoDelay()), then after a successful connection to the remote socket, this option will be set on the socket. If an error occurs setting the TCP_NODELAY option, the internal flag is set to false (use HTTPClient::getNoDelay() to check the flag's state) and the error code can be retrieved with errno().
HTTPClient::connect() returns nothing
$httpclient.connect();
EVENT_CONNECTING, EVENT_CONNECTED,EVENT_HOSTNAME_LOOKUP, EVENT_HOSTNAME_RESOLVED, EVENT_START_SSL, EVENT_SSL_ESTABLISHED
Table 4.434. Exceptions thrown by HTTPClient::connect()
err | desc |
|---|---|
| The attempt to connect exceeeded the maximum number of redirects allowed for the object. |
| There was an error receiving data on the socket |
| The receive attempt timed out. |
Disconnects from the remote socket if a connection is established (otherwise does nothing).
HTTPClient::disconnect() returns nothing
$httpclient.disconnect();
Sends an HTTP GET request and returns the message body received. In order to get the headers and the body, use the HTTPClient::send() method instead. If necessary, a connection will be established via an implicit call to HTTPClient::connect() before sending the message.
HTTPClient::get(string $path, hash $headers = hash(), reference $info) returns any
HTTPClient::get(string $path, hash $headers = hash()) returns any
$html = $httpclient.get("/path/file.html");
EVENT_CONNECTING, EVENT_CONNECTED, EVENT_HOSTNAME_LOOKUP, EVENT_HOSTNAME_RESOLVED, EVENT_START_SSL, EVENT_SSL_ESTABLISHED, EVENT_HTTP_SEND_MESSAGE, EVENT_PACKET_SENT, EVENT_HTTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_HTTP_CONTENT_LENGTH, EVENT_HTTP_CHUNKED_START, EVENT_HTTP_CHUNKED_END, EVENT_HTTP_CHUNKED_DATA_RECEIVED, EVENT_HTTP_CHUNK_SIZE, EVENT_HTTP_FOOTERS_RECEIVED, EVENT_HTTP_REDIRECT
Table 4.435. Arguments for HTTPClient::get()
|
Argument |
Description |
|---|---|
| The path for the message (i.e. '/path/resource?method¶m=value') |
An optional hash of headers to include in the message. | |
| An optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request. |
Table 4.437. Exceptions thrown by HTTPClient::get()
|
err |
desc |
|---|---|
|
|
timeout on response from HTTP server |
|
|
error communicating with HTTP server |
Sends an HTTP HEAD request and returns the headers received. If necessary, a connection will be established via an implicit call to HTTPClient::connect() before sending the message.
HTTPClient::head(string $path, hash $headers = hash(), reference $info) returns hash
HTTPClient::head(string $path, hash $headers = hash()) returns hash
$response = $httpclient.head("/path");
EVENT_CONNECTING, EVENT_CONNECTED, EVENT_HOSTNAME_LOOKUP, EVENT_HOSTNAME_RESOLVED, EVENT_START_SSL, EVENT_SSL_ESTABLISHED, EVENT_HTTP_SEND_MESSAGE, EVENT_PACKET_SENT, EVENT_HTTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_HTTP_CONTENT_LENGTH, EVENT_HTTP_CHUNKED_START, EVENT_HTTP_CHUNKED_END, EVENT_HTTP_CHUNKED_DATA_RECEIVED, EVENT_HTTP_CHUNK_SIZE, EVENT_HTTP_FOOTERS_RECEIVED, EVENT_HTTP_REDIRECT
Table 4.438. Arguments for HTTPClient::head()
Argument | Description |
|---|---|
| The path for the message (i.e. '/path/resource?method¶m=value') |
An optional hash of headers to include in the message. | |
| An optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request. |
Table 4.439. Return Values for HTTPClient::head()
|
Return Type |
Description |
|---|---|
|
The headers received from the HTTP server with all key names converted to lower-case. |
Table 4.440. Exceptions thrown by HTTPClient::head()
|
err |
desc |
|---|---|
|
|
timeout on response from HTTP server |
|
|
error communicating with HTTP server |
Sends an HTTP POST request with a message body and returns the message body received as a response. In order to get the headers and the body, use HTTPClient::send() instead. If necessary, a connection will be established via an implicit call to HTTPClient::connect() before sending the message.
HTTPClient::post(string $path, data $body, hash $headers = hash(), reference $info) returns any
HTTPClient::post(string $path, data $body, hash $headers = hash()) returns any
Table 4.441. Arguments for HTTPClient::post()
Argument | Description |
|---|---|
| The path for the message (i.e. '/path/resource?method¶m=value') |
| The message body to send. |
An optional hash of headers to include in the message. | |
| An optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request. |
Table 4.443. Exceptions thrown by HTTPClient::post()
|
err |
desc |
|---|---|
|
|
timeout on response from HTTP server |
|
|
error communicating with HTTP server |
Sends an HTTP request with the specified method and optional message body and returns headers and optionally the body received as a response in a hash format. If necessary, a connection will be established via an implicit call to HTTPClient::connect() before sending the message.
HTTPClient::send(data $body = binary(), string $method, string $path = "", hash $headers = hash(), bool $getbody = False, reference $info) returns hash
HTTPClient::send(data $body = binary(), string $method, string $path = "", hash $headers = hash(), bool $getbody = False) returns hash
$msg = $httpclient.send($body, "POST", "/path", ("Connection":"Keep-Alive"));
EVENT_CONNECTING, EVENT_CONNECTED, EVENT_HOSTNAME_LOOKUP, EVENT_HOSTNAME_RESOLVED, EVENT_START_SSL, EVENT_SSL_ESTABLISHED, EVENT_HTTP_SEND_MESSAGE, EVENT_PACKET_SENT, EVENT_HTTP_MESSAGE_RECEIVED, EVENT_PACKET_READ, EVENT_HTTP_CONTENT_LENGTH, EVENT_HTTP_CHUNKED_START, EVENT_HTTP_CHUNKED_END, EVENT_HTTP_CHUNKED_DATA_RECEIVED, EVENT_HTTP_CHUNK_SIZE, EVENT_HTTP_FOOTERS_RECEIVED, EVENT_HTTP_REDIRECT
Table 4.444. Arguments for HTTPClient::send()
Argument | Description |
|---|---|
| The message body to send; use NOTHING to send to body. |
| The name of the HTTP method ( |
| The path for the message (i.e. '/path/resource?method¶m=value') |
An optional hash of headers to include in the message. | |
| If this argument is true, then the object will try to receive a message body even if no |
| An optional reference to an lvalue that will be used as an output variable giving a hash of request headers and other information about the HTTP request. |
Table 4.445. Return Values for HTTPClient::send()
|
Return Type |
Description |
|---|---|
|
The headers received from the HTTP server with all key names converted to lower-case. The message body, if any, will be assigned to the value of the 'body' key. |
Table 4.446. Exceptions thrown by HTTPClient::send()
|
err |
desc |
|---|---|
|
|
timeout on response from HTTP server |
|
|
error communicating with HTTP server |
|
|
invalid HTTP method passed |
Sets the default connect timeout in milliseconds. Negative numbers mean use the default system timeout. Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.).
HTTPClient::setConnectTimeout(softint $timeout_ms = -1) returns nothing
HTTPClient::setConnectTimeout(date $timeout) returns nothing
$httpclient.setConnectTimeout(2m); # sets timeout to 2 minutes
Sets the default read timeout in milliseconds. Zero means immediate timeout (will return data only if it is already available), and negative numbers mean never timeout (wait forever for data). Note that like all Qore functions and methods taking timeout values, a relative date/time value can be used to make the units clear (i.e. 2m = two minutes, etc.).
HTTPClient::setTimeout(softint $timeout_ms = -1) returns nothing
HTTPClient::setTimeout(date $timeout) returns nothing
$httpclient.setTimeout(2m); # sets timeout to 2 minutes
Returns the connect timeout as an integer in milliseconds. Negative numbers mean the default system timeout is used instead.
HTTPClient::getConnectTimeout() returns int
$timeout = $httpclient.getConnectTimeout();
Table 4.449. Return Values for HTTPClient::getConnectTimeout()
|
Return Type |
Description |
|---|---|
|
The connect timeout value in milliseconds |
Returns the default read timeout as an integer in milliseconds. Zero means immediate timeout (only returns data if it is already available), and negative numbers mean never timeout (wait forever for data).
HTTPClient::getTimeout() returns int
$timeout = $httpclient.getTimeout();
Table 4.450. Return Values for HTTPClient::getTimeout()
|
Return Type |
Description |
|---|---|
|
The read timeout value in milliseconds |
Sets the HTTP protocol version string for headers in outgoing messages, allowed values are '1.0' and '1.1'.
HTTPClient::setHTTPVersion(string $ver) returns nothing
$httpclient.setHTTPVersion("1.1");
Table 4.451. Arguments for HTTPClient::setHTTPVersion()
|
Argument |
Description |
|---|---|
|
either '1.0' or '1.1' for the HTTP protocol compliance version. |
Table 4.452. Exceptions thrown by HTTPClient::setHTTPVersion()
|
err |
desc |
|---|---|
|
|
invalid HTTP version passed (allowed values: '1.0', '1.1'). |
Returns the HTTP protocol version string used in outgoing messages.
HTTPClient::getHTTPVersion() returns string
$version = $httpclient.getHTTPVersion();
Table 4.453. Return Values for HTTPClient::getHTTPVersion()
|
Return Type |
Description |
|---|---|
|
The HTTP protocol version string used in outgoing messages (either '1.0' or '1.1'). |
Sets the object to make a secure SSL/TLS connection on the next connect if the passed argument is True, or an unencrypted cleartext connection if it is False. This method overrides the default behaviour for the protocol set for the object.
Note that the behavior of this method when called with no argument changed in version 0.8.0; prior to version 0.8.0 calling this method with no argument would turn off secure mode; the behavior was changed to the current functionality in order to make the usage of this method consistent with other methods of the same name and to make it more logical.
HTTPClient::setSecure(softbool $secure = True) returns nothing
$httpclient.setSecure(True);
Table 4.454. Arguments for HTTPClient::setSecure()
|
Argument |
Description |
|---|---|
|
If |
Returns True if the current connection is encrypted, False if not.
HTTPClient::isSecure() returns bool
$bool = $httpclient.isSecure();
Table 4.455. Return Values for HTTPClient::isSecure()
|
Return Type |
Description |
|---|---|
|
Returns |
Returns a string code giving the result of verifying the remote certificate or NOTHING if an encrypted connection is not established. Return value are the keys described in the X509_VerificationReasons hash constant. This hash can also be used to generate a textual description of the verification result.
HTTPClient::verifyPeerCertificate() returns any
my any $str = $httpclient.verifyPeerCertificate();
Returns the name of the cipher for an encrypted connection.
HTTPClient::getSSLCipherName() returns any
my any $str = $httpclient.getSSLCipherName();
Returns the version of the cipher for an encrypted connection.
HTTPClient::getSSLCipherVersion() returns any
my any $str = $httpclient.getSSLCipherVersion();
Sets the string encoding for the object; any strings deserialized with this object will be tagged with this character encoding.
HTTPClient::setEncoding(string $encoding) returns nothing
$httpclient.setEncoding("ISO-8859-1");
Table 4.459. Arguments for HTTPClient::setEncoding()
|
Argument |
Description |
|---|---|
|
The string encoding to use for this object. |
Table 4.460. Exceptions thrown by HTTPClient::setEncoding()
|
err |
desc |
|---|---|
|
|
missing encoding parameter from method call |
Returns the character encoding used for the object
HTTPClient::getEncoding() returns string
$str = $httpclient.getEncoding();
Table 4.461. Return Values for HTTPClient::getEncoding()
|
Return Type |
Description |
|---|---|
|
The character encoding used for the object. |
Sets a Queue object to receive HTTPClient and Socket events. To remove the event queue and stop monitoring events, pass NOTHING to the method. See Event Handling for more information.
HTTPClient::setEventQueue() returns nothing
HTTPClient::setEventQueue(Queue $queue) returns nothing
$httpclient.setEventQueue($queue);
Returns the TCP_NODELAY setting for the HTTPClient object. See also HTTPClient::setNoDelay().
HTTPClient::getNoDelay() returns bool
$nodelay = $httpclient.getNoDelay();
Table 4.463. Return Value for HTTPClient::getNoDelay()
Return Type | Description |
|---|---|
The |
Sets the TCP_NODELAY setting for the HTTPClient object; when this setting is True, then data will be immediately sent out over the HTTPClient object's socket, when it is False, then data transmission may be delayed to be packaged with other data for the same target.
Delayed data transmissions may cause problems when the sender immediately closes the socket after sending data; in this case the receiver may not get the data even though the send succeeded.
Note that if no value is given to the method, the argument will be assumed to be False, and output buffering will be turned on for the HTTPClient object, which may be the opposite of what the programmer intends, therefore it's recommended to always pass an argument to this method.
If the socket is not connected when this call is made, then an internal flag is set and the TCP_NODELAY option is enabled when the next connection is established. If the socket is connected, then if an error occurs setting the TCP_NODELAY option on the socket, this method will return a non-zero error code; the actual error can be checked with the errno() function.
See also HTTPClient::getNoDelay().
HTTPClient::setNoDelay(softbool $nodelay = True) returns int
$httpclient.setNoDelay(True);
Table 4.464. Arguments for HTTPClient::setNoDelay()
Argument | Description |
|---|---|
| The |
Table 4.465. Return Value for HTTPClient::setNoDelay()
Return Type | Description |
|---|---|
0 for success, non-zero for errors. To get error information, see errno() and strerror(). |
Returns the connection state of the HTTPClient object. Connections are implicitly established whenever a method is callde requiring a connection; to explicitly establish a connection, see HTTPClient::connect().
HTTPClient::isConnected() returns bool
my bool $connected = $httpclient.isConnected();
Table 4.466. Return Value for HTTPClient::isConnected()
Return Type | Description |
|---|---|
The connection state of the HTTPClient object. |