tencent cloud

All product documents
Tencent Cloud Observability Platform
Basic Usage
Last updated: 2025-03-10 22:14:18
Basic Usage
Last updated: 2025-03-10 22:14:18
PTS supports the GET, POST, PUT, PATCH, OPTIONS, DELETE, and HEAD requests of the HTTP protocol.

Script Writing

HTTP GET Request

// Send a http get request
import http from 'pts/http';
import { check, sleep } from 'pts';

export default function () {
// simple get request
const resp1 = http.get('http://httpbin.org/get');
console.log(resp1.body);
// if resp1.body is a json string, resp1.json() transfer json format body to a json object
console.log(resp1.json());
check('status is 200', () => resp1.statusCode === 200);

// sleep 1 second
sleep(1);

// get request with headers and parameters
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); // 'value1'
check('body.args.name1 equals value1', () => resp2.json().args.name1 === 'value1');
};

HTTP POST Request

// Send a 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); // 12345
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.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support