httpClient

With DolphinDB's httpClient plugin, you can send HTTP requests and send emails via SMTP. The plugin uses the third-party cURL library to perform HTTP requests and send emails.

Before using the email-sending feature, make sure that the target mail server support SMTP and have the corresponding service port enabled. If the email service provider has not enabled the relevant services by default, you must first enable SMTP for the sending mailbox and obtain the password or authorization code required by the provider.

Installation

Required server version: DolphinDB 2.00.10 or higher, Shark

Supported OS: Windows x64, Linux x64, Linux ARM, and Linux ABI.

Installation Steps:

  1. Use listRemotePlugins to check plugin information in the plugin repository.
    login("admin", "123456")
    listRemotePlugins()
  2. Use installPlugin for plugin installation.
    installPlugin("httpClient")
  3. Use loadPlugin to load the plugin before using the plugin methods.
    loadPlugin("httpClient")

Method References

httpGet

Syntax

httpGet(url, [params], [timeout], [headers])

Details

Sends an HTTP GET request.

Returns a dictionary containing the following keys:

  • responseCode: HTTP status code.
  • headers: HTTP response header.
  • text: HTTP response body.
  • elapsed: HTTP request elapsed time.

Parameters

  • url: A STRING scalar indicating the URL of the HTTP request.
  • params: A STRING scalar or a dictionary with STRING keys and values, indicating the parameters of the HTTP request. After specified, params will be appended to the end of url. Suppose url is specified as "http://www.dolphindb.com":
    • If params is a string (e.g., "example"), the URL of the HTTP request would be "http://www.dolphindb.com?example";
    • If params is a dictionary (e.g., with 2 key-value pairs "name"->"ddb" and "id"->"111"), the URL of the HTTP request would be "http://www.dolphindb.com?id=111&name=ddb".
  • timeout: An integer indicating the timeoout duration in milliseconds.
  • headers: A STRING scalar or a dictionary with STRING keys and values, indicating the headers of the HTTP request.
    • If headers is a dictionary (e.g., with 2 key-value pairs "groupName"->"dolphindb" and "groupId"->"11"), the two headers "groupId: 11" and "groupName: dolphindb" will be appended to the HTTP request;
    • If headers is a string, it must have the pattern <key>: <value> and will be appended as a header to the request.
  • config: A dictionary with STRING keys indicating configuration items.

Examples

loadPlugin('/home/DolphinDBPlugin/httpClient/PluginHttpClient.txt');
param = dict(string,string);
header = dict(string,string);
param['name'] = 'example';
param['id'] = '111';
header['groupName'] = 'dolphindb';
header['groupId'] = '11';
//Please set up your own httpServer ex.(python -m SimpleHTTPServer 8900)
url = "localhost:8900";
res = httpGet(url,param,1000,header);

httpPost

Syntax

httpPost(url, [params], [timeout], [headers])

Details

Sends an HTTP POST request.

Returns a dictionary containing the same keys as httpGet.

Parameters

Most parameters of httpPost are the same as those of httpGet; only the differing parameters are described here.

  • params: A STRING scalar or a dictionary with STRING keys and values, indicating the parameters of the HTTP request. After specified, params will be included in the HTTP message body.

Examples

loadPlugin('/home/DolphinDBPlugin/httpClient/PluginHttpClient.txt');
param=dict(string,string);
header=dict(string,string);
param['name']='example';
param['id']='111';
header['groupName']='dolphindb';
header['groupId']='11';
//Please set up your own httpServer ex.(python -m SimpleHTTPServer 8900)
url = "localhost:8900";
res = httpClient::httpPost(url,toStdJson(param),1000,header);

httpPut

Syntax

httpPut(url, [params], [timeout], [headers], [config])

Details

Sends an HTTP PUT request.

Returns a dictionary containing the same keys as httpGet.

Parameters

httpPut contains the same parameters as httpGet.

httpDelete

Syntax

httpDelete(url, [params], [timeout], [headers], [config])

Details

Sends an HTTP DELETE request.

Returns a dictionary containing the same keys as httpGet.

Parameters

httpDelete contains the same parameters as httpGet.

emailSmtpConfig

Syntax

emailSmtpConfig(domain,host,[port=25])

Details

Configures the mail server address and port for the specified email domain. Calling this function only saves or updates the mail server configuration; it does not immediately connect to the mail server or send email.

Parameters

  • domain: A STRING scalar indicating the domain name of the email address, such as "gmail.com" and "yahoo.com".
  • host: A STRING scalar indicating the SMTP server address.
  • port: An integer indicating the port number of the email server. The default value is 25.

Examples

domain = "qq.com";
host = "smtp.qq.com";
port = 25;
emailSmtpConfig(domain,host,[port=25]);

sendEmail

Syntax

sendEmail(userId,pwd,recipient,subject,body)

Details

Sends emails. Before sending an email, configure the mail server for the sender's email domain through emailSmtpConfig.

Returns a dictionary containing the following keys:

  • userId: The sender's email account.
  • recipient: A set of strings indicating the receivers' email accounts.
  • responseCode: The response code returned by the HTTP request.
  • headers: The headers returned by the HTTP request.
  • text: The text returned by the HTTP request.
  • elapsed: The time elapsed for the HTTP request.

Parameters

  • userId: A STRING scalar indicating the sender’s email account.
  • pwd: A STRING scalar indicating the sender’s email password.
  • recipient: A STRING scalar or vector indicating the receivers' email accounts.
  • subject: A STRING scalar indicating the email theme.
  • body: A STRING scalar indicating the email body.

Examples

Example 1: Send an email.

sendEmail('MailFrom@xxx.com','xxxxx','Maildestination@xxx.com','This is a subject','It is a text');
recipient = 'Maildestination@xxx.com''Maildestination2@xxx.com''Maildestination3@xxx.com';
res = sendEmail('MailFrom@xxx.com','xxxxx',recipient,'This is a subject','It is a text');