httpfile()

Description:

Package the returned result of URL as the file flow.

Syntax:  

httpfile(url:cs,param:cs:method;header)

Note:

The function packages the returned result of URL string of HTTP service into a file flow and returns it, which can only be retrieved with segmentation forbidden.

Parameter:  

url

HTTP service in the URL string format.

Parameter port is the port number configured in Http Server. The dfx path is the one relative to the main directory configured in Tool -> Options -> Environment.

Two scenarios about the syntax of writing a URL for performing an HTTP service:

I. esProc style

  Syntax of writing a URL when using esProc’s HTTP service:

  http:// IP:port /dfx1.dfx()

  http:// IP:port /dfx1.dfx(arg1,arg2,...)

http://IP: port/dfx1.dfx(...)dfx2.dfx

http://[IP6]:port /dfx1.dfx()

1. There’s only one dfx file. If the dfx file has parameters, write them in order in the parentheses after the file; use comma to separate the multiple parameters. If the dfx file hasn’t parameters, the parentheses are empty; in this case the format of the file’s return value is what a user expects.

2. There are two dfx files. When the return value format a user wants is different from the format of the return value in dfx1 file, dfx2 file is used to change the format of the return value in dfx1 into a desired one. The syntax for dfx1 is the same as the that for the dfx file in the first scenario, but here the file supports only the single result set. dfx2 file is a program with only one parameter, which is the return value of dfx1 file.

  dfx2 file converts the format of the return value in dfx1 file into a desired one and return it as a result. For example, in the table sequence returned by dfx1 file, fields are by default separated by “|”; you can change dfx1’s return value in dfx2 to use the blank space as the separator.

If the second result set, which must contain strings, is returned, it is treated as the header.

3.  For IPv6, bracket the IP address with [].

II. Regular style

   Syntax of writing a URL:

http://ip:port/splfile?argi=vi&... , where splfile does not contain the extension because parameters after the quotation mark cannot be read if it does; the program will search for the file according to extension in the order of .splx, .spl and .dfx.

Ⅲ. result style

When the spl script file is located in a subdirectory under the main directory, you can use result type to call it.

Syntax of writing a URL:

http://IP:port /Path/splfile  Call a spl script file without parameters

http://IP:port /Path/splfile/argvalue1/argvalue2,... Call a spl script file containing parameters

Path represents the splfile path relative to the main directory;

splfile is the name of spl script file, whose extension will be omitted at the call and searched in the order of .splx, .spl and .dfx;

argvalue1/argvalue2],... is the value of parameter splfile; multiple parameters are separated by “/”.

Note: To access database data from splfile, configure the value of autoConnect property as true in raqsoftconfig.xml’s DB node; you can’t connect to the database if skipping this configuration.

cs

Character set, which supports JVM's built-in character set, and which by default is the default value of virtual machine.

param

 

method

 

header

A parameter submitted using the method specified in parameter method with a syntax like p1=v1&p2=v2…. can be omitted.

The method used to pass parameter param’s value; its value is GET or POST (default is POST)

The header property can have multiple items, like headerName1:value1,headerName2:value2,... (the format is "property":"value",…); or can be omitted. The execution of .property() function over a returned file object will return the header property.

Return value:

File flow

Example:

 

A

 

1

=httpfile("http:// localhost:9090/p1.dfx()":"GBK").import@t()

Here’s the p1.dfx file:

Load p1.dfx file from the http server, with the charset as GBK.

2

=httpfile("http://localhost:9090/p2.dfx(3)":"GBK").import@t()

Here’s the p2.dfx file where StuId is the parameter.

3 is the value of parameter in p2.dfx file.

3

=httpfile("http://localhost:9090/p3.dfx(3Class%20two)":"GBK").import@t()

Here’s the p3.dfx file where StuId and Class are the parameters.

The two parameters are separated by a comma.

4

=httpfile("http://localhost:9090/http2.dfx()").import@t()

Here’s http2.dfx :

 

The returned result:

 

5

=httpfile("http://127.0.0.1:9090/http2.dfx()http3.dfx").import@t()

Here’s the http3.dfx:

The returned result:

 

By default the execution of http2.dfx file returns a sequence of STATE values. To return comma-separated strings, we process the result of http2.dfx using another dfx file http3.dfx.

6

=httpfile("http:// 192.168.0.131:6080/myweb/servlet/testServlet?table=employee&type=json")

testServlet returns a string of employee data in the JSON format.

7

=httpfile("http://localhost:6080/myweb/servlet/testServlet":"GBK","table=employee&type=json":"GBK":"POST")

Use POST method to pass parameter.

8

=httpfile("http://127.0.0.1:8182/scada/v1/uaes/datapoint/history/rawvalue/rtdb/access","{\"nodeIds\":[\"ns=102;s=AI_002_0600.PV\"], \"startTime\":\"2018/6/28 13:10:00\", \"endTime\":\"2018/6/28 13:11:0\", \"returnBounds\":\"false\", \"maxSizePerNode\":\"10\"}"; "Content-Type":"application/json")

Pass parameter using JSON method at the server side; write parameter param in the form of a JSON string, and specify header property as Content-Type, which is separated from the parameter before by a semicolon.

9

=httpfile("http://127.0.0.1:8503/sr/pm/gypb/3/15").read()

Here’s gypb.dfx:

Set a cellset parameter:

result style is used. “/sr/pm” shows a position relative to the main directory; “gypb” points to the dfx fle gypb.dfx, and “3/15” means that parameter id’s value is 3 and parameter parent’s value is 15.

10

=httpfile("http://192.168.74.1:8508/dc/22").read()

If the file is under the main directory, the port number can be directly followed by /splfile instead of the path. Here the URL means that dc.dfx is saved under the main directory and the parameter value is 22.

11

=httpfile("http://[fe80::2918:abe0:3017:8401%15]:8503/emp.dfx()":"GBK").import@t()

Load emp.dfx file through http service via IPv6 connectivity using GBK charset.

12

=httpfile("http://127.0.0.1:8503/emp?dept=HR&salary=5000 ").import@t()

Below is content of file emp.Splx:

Below are cellset parameters:

Use regular style for the URL.

httpupload()

Description:

Upload parameters and files to an URL using the HTTP protocol.

Syntax:

httpupload(url:cs,ai:vi;fi:fni)

Note:

The function uploads parameter ai and file parameter fi to an URL through HTTP protocol and returns character set cs or null or failure information when the upload fails.. Parameter ai can be absent but there must be at least one file parameter uploaded. Multiple parameters and file parameters can be uploaded as needed.

Parameter:

url

HTTP service’s URL string format

cs

The charset of returned content, which is UTF-8 by default

ai

Parameters

vi

Parameter values that will be parsed as a string

fi

File parameters

fni

The file path or BLOB

Return value:

The content of certain character set

Example:

 

A

 

1

http://survey.raqsoft.com.cn/upload

 

2

=file("D:/emp.txt").read@b()

 

INCLUDEPICTURE "H:\\mk:@MSITStore:D:\\0903esproc\\esProc\\documents\\zh\\函数参考.chm::\\topics\\函数参考.files\\image1224.png" \* MERGEFORMAT \d.

Read the file as BLOB data.

3

=httpupload(A1:"GBK","userid":"1001","updir":"uploadFiles";"file1":"D:/1.png","file2":A2)

Parameters and the files have been uploaded successfully and the content of GBK charset is returned through the URL.

4

=httpupload(A1;"file2":"D:/emp.txt")

 A file has been uploaded successfully and the content of UTF-8 charset is returned through the URL.

5

=httpupload("http://survey.raqsoft.com.cn";"file2":A2)

Null is returned since the file upload fails.