Easy

net.Curl. Easy

net.Curl.Easy is used for configuration.
net.Curl.Multi will perform web requests by using net.Curl.Multi#addHandle.

Retrieve (GET) the content of a website:

// Create a utf-8 decoder
const decoder = new TextDecoder('utf-8');
// Create a curl Easy instance
var curl = new net.Curl.Easy();
// On HMI we do not have CA root certificate chains, so we will not verify the certificate
curl.setOpt(net.Curl.Easy.option.SSL_VERIFYPEER, false);
// Fill in the url
curl.setOpt(net.Curl.Easy.option.URL, "http://www.weintek.com/");
// This is a GET request
curl.setOpt(net.Curl.Easy.option.HTTPGET, true);

var responseData = "";
curl.setOpt(net.Curl.Easy.option.WRITEFUNCTION, function (buf) {
    var resp = decoder.decode(buf);
    responseData += resp;
});

// To run the request, we use Multi to do this.
// First, create a multi instance
var multi = new net.Curl.Multi();

// Then setup the event callback
multi.onMessage((easyHandle, result) => {
    var error = net.Curl.Easy.strError(result);
    var responseCode = easyHandle.getInfo(net.Curl.info.RESPONSE_CODE);
    // responseData is written by WRITEFUNCTION
    console.log(error, responseCode, responseData);
    multi.removeHandle(easyHandle);
});

// Perform the request
multi.addHandle(curl);

Members

(static) code :Number

The result code passed in net.Curl.Multi~onMessageCallback.

Code Description
OK No error
UNSUPPORTED_PROTOCOL Unsupported protocol
FAILED_INIT Failed initialization
URL_MALFORMAT URL using bad/illegal format or missing URL
NOT_BUILT_IN A requested feature, protocol or option was not found built-in in this libcurl due to a build-time decision.
COULDNT_RESOLVE_PROXY Couldn't resolve proxy name
COULDNT_RESOLVE_HOST Couldn't resolve host name
COULDNT_CONNECT Couldn't connect to server
FTP_WEIRD_SERVER_REPLY FTP: weird server reply
REMOTE_ACCESS_DENIED Access denied to remote resource
FTP_ACCEPT_FAILED FTP: The server failed to connect to data port
FTP_ACCEPT_TIMEOUT FTP: Accepting server connect has timed out
FTP_PRET_FAILED FTP: The server did not accept the PRET command.
FTP_WEIRD_PASS_REPLY FTP: unknown PASS reply
FTP_WEIRD_PASV_REPLY FTP: unknown PASV reply
FTP_WEIRD_227_FORMAT FTP: unknown 227 response format
FTP_CANT_GET_HOST FTP: can't figure out the host in the PASV response
HTTP2 Error in the HTTP2 framing layer
FTP_COULDNT_SET_TYPE FTP: couldn't set file type
PARTIAL_FILE Transferred a partial file
FTP_COULDNT_RETR_FILE FTP: couldn't retrieve (RETR failed) the specified file
QUOTE_ERROR Quote command returned error
HTTP_RETURNED_ERROR HTTP response code said error
WRITE_ERROR Failed writing received data to disk/application
UPLOAD_FAILED Upload failed (at start/before it took off)
READ_ERROR Failed to open/read local data from file/application
OUT_OF_MEMORY Out of memory
OPERATION_TIMEDOUT Timeout was reached
FTP_PORT_FAILED FTP: command PORT failed
FTP_COULDNT_USE_REST FTP: command REST failed
RANGE_ERROR Requested range was not delivered by the server
HTTP_POST_ERROR Internal problem setting up the POST
SSL_CONNECT_ERROR SSL connect error
BAD_DOWNLOAD_RESUME Couldn't resume download
FILE_COULDNT_READ_FILE Couldn't read a file:// file
LDAP_CANNOT_BIND LDAP: cannot bind
LDAP_SEARCH_FAILED LDAP: search failed
FUNCTION_NOT_FOUND A required function in the library was not found
ABORTED_BY_CALLBACK Operation was aborted by an application callback
BAD_FUNCTION_ARGUMENT A libcurl function was given a bad argument
INTERFACE_FAILED Failed binding local connection end
TOO_MANY_REDIRECTS Number of redirects hit maximum amount
UNKNOWN_OPTION An unknown option was passed in to libcurl
TELNET_OPTION_SYNTAX Malformed telnet option
PEER_FAILED_VERIFICATION SSL peer certificate or SSH remote key was not OK
GOT_NOTHING Server returned nothing (no headers, no data)
SSL_ENGINE_NOTFOUND SSL crypto engine not found
SSL_ENGINE_SETFAILED Can not set SSL crypto engine as default
SSL_ENGINE_INITFAILED Failed to initialise SSL crypto engine
SEND_ERROR Failed sending data to the peer
RECV_ERROR Failure when receiving data from the peer
SSL_CERTPROBLEM Problem with the local SSL certificate
SSL_CIPHER Couldn't use specified SSL cipher
SSL_CACERT Peer certificate cannot be authenticated with given CA certificates
SSL_CACERT_BADFILE Problem with the SSL CA cert (path? access rights?)
BAD_CONTENT_ENCODING Unrecognized or bad HTTP Content or Transfer-Encoding
LDAP_INVALID_URL Invalid LDAP URL
FILESIZE_EXCEEDED Maximum file size exceeded
USE_SSL_FAILED Requested SSL level failed
SSL_SHUTDOWN_FAILED Failed to shut down the SSL connection
SSL_CRL_BADFILE Failed to load CRL file (path? access rights?, format?)
SSL_ISSUER_ERROR Issuer check against peer certificate failed
SEND_FAIL_REWIND Send failed since rewinding of the data stream failed
LOGIN_DENIED Login denied
TFTP_NOTFOUND TFTP: File Not Found
TFTP_PERM TFTP: Access Violation
REMOTE_DISK_FULL Disk full or allocation exceeded
TFTP_ILLEGAL TFTP: Illegal operation
TFTP_UNKNOWNID TFTP: Unknown transfer ID
REMOTE_FILE_EXISTS Remote file already exists
TFTP_NOSUCHUSER TFTP: No such user
CONV_FAILED Conversion failed
CONV_REQD Caller must register CURLOPT_CONV_ callback options
REMOTE_FILE_NOT_FOUND Remote file not found
SSH Error in the SSH layer
AGAIN Socket not ready for send/recv
RTSP_CSEQ_ERROR RTSP CSeq mismatch or invalid CSeq
RTSP_SESSION_ERROR RTSP session error
FTP_BAD_FILE_LIST Unable to parse FTP file list
CHUNK_FAILED Chunk callback failed
NO_CONNECTION_AVAILABLE The max connection limit is reached
SSL_PINNEDPUBKEYNOTMATCH SSL public key does not match pinned public key
SSL_INVALIDCERTSTATUS SSL server certificate status verification FAILED
Type:
  • Number
Example

net.Curl.Easy.option.VERBOSE

var curl = new net.Curl.Easy();
// enable verbose mode
curl.setOpt(curl.option.VERBOSE, true);

(static) option :Number

Availabe options are listed below:

BEHAVIOR OPTIONS

Option Description
VERBOSE Display verbose information
HEADER Include the header in the body output
NOPROGRESS Shut off the progress meter

CALLBACK OPTIONS

Option Description
WRITEFUNCTION Callback for writing data
READFUNCTION Callback for reading data
SEEKFUNCTION Callback for seek operations
XFERINFOFUNCTION Callback for progress meter
HEADERFUNCTION Callback for writing received headers

ERROR OPTIONS

Option Description
FAILONERROR Fail on HTTP 4xx errors

NETWORK OPTIONS

Option Description
URL URL to work on
PROTOCOLS Allowed protocols
REDIR_PROTOCOLS Protocols to allow redirects to
PROXY Proxy to use
PROXYPORT Proxy port to use
PROXYTYPE Proxy type
NOPROXY Filter out hosts from proxy use
HTTPPROXYTUNNEL Tunnel through the HTTP proxy
SOCKS5_GSSAPI_SERVICE Socks5 GSSAPI service name
SOCKS5_GSSAPI_NEC Socks5 GSSAPI NEC mode
INTERFACE Bind connection locally to this
LOCALPORT Bind connection locally to this port
LOCALPORTRANGE Bind connection locally to port range
DNS_CACHE_TIMEOUT Timeout for DNS cache
BUFFERSIZE Ask for smaller buffer size
PORT Port number to connect to
TCP_NODELAY Disable the Nagle algorithm
ADDRESS_SCOPE IPv6 scope for local addresses
TCP_KEEPALIVE Enable TCP keep-alive
TCP_KEEPIDLE Idle time before sending keep-alive
TCP_KEEPINTVL Interval between keep-alive probes

NAMES and PASSWORDS OPTIONS (Authentication)

Option Description
USERPWD User name and password
PROXYUSERPWD Proxy user name and password
USERNAME User name
PASSWORD Password
LOGIN_OPTIONS Login options
PROXYUSERNAME Proxy user name
PROXYPASSWORD Proxy password
HTTPAUTH HTTP server authentication methods
TLSAUTH_USERNAME TLS authentication user name
TLSAUTH_PASSWORD TLS authentication password
PROXYAUTH HTTP proxy authentication methods
SASL_IR Enable SASL initial response
XOAUTH2_BEARER OAuth2 bearer token

HTTP OPTIONS

Option Description
AUTOREFERER Automatically set Referer: header
ACCEPT_ENCODING Accept-Encoding and automatic decompressing data
TRANSFER_ENCODING Request Transfer-Encoding
FOLLOWLOCATION Follow HTTP redirects
UNRESTRICTED_AUTH Do not restrict authentication to original host
MAXREDIRS Maximum number of redirects to follow
POSTREDIR How to act on redirects after POST
PUT Issue a HTTP PUT request
POST Issue a HTTP POST request
POSTFIELDS Send a POST with this data
POSTFIELDSIZE The POST data is this big
POSTFIELDSIZE_LARGE The POST data is this big
COPYPOSTFIELDS Send a POST with this data - and copy it
HTTPPOST Multipart formpost HTTP POST
REFERER Referer: header
USERAGENT User-Agent: header
HTTPHEADER Custom HTTP headers
HEADEROPT Control custom headers
PROXYHEADER Custom HTTP headers sent to proxy
HTTP200ALIASES Alternative versions of 200 OK
COOKIE Cookie(s) to send
COOKIESESSION Start a new cookie session
HTTPGET Do a HTTP GET request
HTTP_VERSION HTTP version to use
IGNORE_CONTENT_LENGTH Ignore Content-Length
HTTP_CONTENT_DECODING Disable Content decoding
HTTP_TRANSFER_DECODING Disable Transfer decoding
EXPECT_100_TIMEOUT_MS 100-continue timeout

SMTP OPTIONS

Option Description
MAIL_FROM Address of the sender
MAIL_RCPT Address of the recipients
MAIL_AUTH Authentication address

PROTOCOL OPTIONS

Option Description
TRANSFERTEXT Use text transfer
PROXY_TRANSFER_MODE Add transfer mode to URL over proxy
CRLF Convert newlines
RANGE Range requests
RESUME_FROM Resume a transfer
RESUME_FROM_LARGE Resume a transfer
CUSTOMREQUEST Custom request/method
FILETIME Request file modification date and time
DIRLISTONLY List only
NOBODY Do not get the body contents
INFILESIZE Size of file to send
INFILESIZE_LARGE Size of file to send
UPLOAD Upload data
MAXFILESIZE Maximum file size to get
MAXFILESIZE_LARGE Maximum file size to get
TIMECONDITION Make a time conditional request
TIMEVALUE Time value for the time conditional request

CONNECTION OPTIONS

Option Description
TIMEOUT Timeout for the entire request
TIMEOUT_MS Millisecond timeout for the entire request
LOW_SPEED_LIMIT Low speed limit to abort transfer
LOW_SPEED_TIME Time to be below the speed to trigger low speed abort
MAX_SEND_SPEED_LARGE Cap the upload speed to this
MAX_RECV_SPEED_LARGE Cap the download speed to this
MAXCONNECTS Maximum number of connections in the connection pool
FRESH_CONNECT Use a new connection
FORBID_REUSE Prevent subsequent connections from re-using this
CONNECTTIMEOUT Timeout for the connection phase
CONNECTTIMEOUT_MS Millisecond timeout for the connection phase
IPRESOLVE IP version to resolve to
CONNECT_ONLY Only connect, nothing else
USE_SSL Use TLS/SSL
RESOLVE Provide fixed/fake name resolves
DNS_INTERFACE Bind name resolves to this interface
DNS_LOCAL_IP4 Bind name resolves to this IP4 address
DNS_LOCAL_IP6 Bind name resolves to this IP6 address
DNS_SERVERS ?
ACCEPTTIMEOUT_MS Timeout for waiting for the server's connect back to be accepted

SSL and SECURITY OPTIONS

Option Description
SSLCERTTYPE Client cert type
SSLKEYTYPE Client key type
KEYPASSWD Client key password
SSL_ENABLE_ALPN Enable use of ALPN
SSL_ENABLE_NPN Enable use of NPN
SSLENGINE Use identifier with SSL engine
SSLENGINE_DEFAULT Default SSL engine
SSLVERSION SSL version to use
SSL_VERIFYHOST Verify the host name in the SSL certificate
SSL_VERIFYPEER Verify the SSL certificate
CERTINFO Extract certificate info
PINNEDPUBLICKEY Set pinned SSL public key
SSL_CIPHER_LIST Ciphers to use
SSL_SESSIONID_CACHE Disable SSL session-id cache
SSL_OPTIONS Control SSL behavior
KRBLEVEL Kerberos security level
GSSAPI_DELEGATION Disable GSS-API delegation
Type:
  • Number
Example

net.Curl.Easy.option.VERBOSE

var curl = new net.Curl.Easy();
// enable verbose mode
curl.setOpt(net.Curl.Easy.option.VERBOSE, true);

Methods

(static) strError(code) → {string}

Return the description of the given code.

Parameters:
Name Type Description
code Number

See net.Curl.Easy.code

Returns:
Type
string

getInfo(info)

Retrieve the information.

Parameters:
Name Type Description
info Number

See net.Curl.info

reset()

This removes any previous options configured with net.Curl.Easy#setOpt

setOpt(option, parameter) → {Number}

Set options for the request.

Parameters:
Name Type Description
option Number

See net.Curl.Easy.option

parameter any
Returns:
Type
Number