PTS supports the GET, POST, PUT, PATCH, OPTIONS, DELETE, and HEAD requests of the HTTP protocol.
Script Writing
HTTP GET Request
import http from 'pts/http';
import { check, sleep } from 'pts';
export default function () {
const resp1 = http.get('http://httpbin.org/get');
console.log(resp1.body);
console.log(resp1.json());
check('status is 200', () => resp1.statusCode === 200);
sleep(1);
const resp2 = http.get('http://httpbin.org/get', {
headers: {
'Connection': 'keep-alive',
'User-Agent': 'pts-engine'
},
query: {
'name1': 'value1',
'name2': 'value2',
}
});
console.log(resp2.json().args.name1);
check('body.args.name1 equals value1', () => resp2.json().args.name1 === 'value1');
};
HTTP POST Request
import http from 'pts/http';
import { check } from 'pts';
export default function () {
const resp = http.post(
'http://httpbin.org/post',
{
user_id: '12345',
},
{
headers: {
'Content-Type': 'application/json',
},
}
);
console.log(resp.json().json.user_id);
check('body.json.user_id equals 12345', () => resp.json().json.user_id === '12345');
}
File Dependency
In the performance testing scenario, you can upload the following types of files to provide status data during the execution of the performance testing task:
Parameter file: It dynamically provides test data in CSV format. That is, when the scenario is executed by each concurrent user (VU), each line of data will be obtained from the parameter file as the test data values for reference by variables in the script. For specific usage, see Using Parameter Files. Request file: It is required for constructing your request, for example, the file that needs to be uploaded. For specific usage, see Using Request Files. Protocol file: It is required for request serialization. For specific usage, see Using Protocol Files.