In the recent version update, Apipost launched plug-in management, which can directly call local script files in pre- and post-execution scripts
import script
Open the directory in "System Settings" - "Plugin Management" and drag the script file to be executed into the folder
execute script
Need to get request parameters:
const requestData = request.request_bodys;
Enter in the pre- and post-execution script input boxes:
let stdout =apt.execute("demo.jar",[requestData]);
As shown in the picture:
console execution result
The jar package log prints out the sign label:
Apipost also supports specifying method calls through the Jar package:
Execute the following code in the pre-execution script to call:
let jarResult = pm.execute("jar package address",[parameter],{
className:'full class name',
method: "method name"
});
console.log(jarResult)
As shown in the figure: we call the get method of JSONObject in JSON.jar
Print it out to get: