HttpClient

The DolphinDB httpClient plugin enables you to send HTTP requests and emails conveniently. The plugin uses the third-party library curl for operations related to HTTP.

Installation (with installPlugin)

Required server version: DolphinDB 2.00.10 or higher

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

Installation Steps:

(1) Use listRemotePlugins to check plugin information in the plugin repository.

Note: For plugins not included in the provided list, you can install through precompiled binaries or compile from source. These files can be accessed from our GitHub repository by switching to the appropriate version branch.

login("admin", "123456")
listRemotePlugins()

(2) Invoke installPlugin for plugin installation.

installPlugin("httpClient")

(3) Use loadPlugin to load the plugin before using the plugin methods.

loadPlugin("httpClient")

Methods References

httpGet

Syntax

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

Details

Send an HTTP GET request.

Return 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

Send an HTTP POST request.

Return a dictionary containing the same keys as httpGet.

Parameters

httpPost contains the same parameters as httpGet.

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 = httpPost(url,param,1000,header);

httpPut

Syntax

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

Details

Send an HTTP PUT request.

Return 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

Send an HTTP DELETE request.

Return a dictionary containing the same keys as httpGet.

Parameters

httpDelete contains the same parameters as httpGet.

emailSmtpConfig

Syntax

emailSmtpConfig(emailName,host,post)

Details

Configure the email server.

Parameters

  • emailName: 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

emailName = "qq.com";
host = "smtp.qq.com";
port = 25;
emailSmtpConfig(emailName,host,port);

sendEmail

Syntax

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

Details

Send an email.

Return 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.

Note: The DolphinDB httpClient plugin adopts the SMTP (Simple Mail Transfer Protocol) for email transmission. Therefore, the email server must support the SMTP protocol and have the SMTP port open. If the email service provider does not have the SMTP port open by default, it is necessary to enable the SMTP service for the sender's email account. If the provider offers an email authorization code, the parameter pwd should be set to this code instead of the email password.

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 indicating the receivers' email accounts.
  • subject: A STRING scalar indicating the email theme.
  • body: A STRING scalar indicating the email body.

Examples

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');