This topic describes how to define a body and provides related examples.
Procedure
Configure the basic request information for an HTTP API. For more information, see Basic request information.
NoteYou can define a body only for a POST, PUT, or PATC request.
Define a body for the HTTP API. The body definition content depends on the value of the Content-Type parameter. The valid values of the parameter are x-www-form-urlencoded, raw, and Custom.
Parameter
Description
x-www-form-urlencoded
Data is encoded as name-value pairs.
NoteWhen you set the parameter to x-www-form-urlencoded, you must decode a defined body before stress testing to avoid errors caused by the repeated encoding of Performance Testing Service (PTS) if the body is encoded. For example, errors occur when PTS re-encodes the value %25 that is encoded from the percent sign (%). Click Decode Body in the upper-right corner of the Body Definition tab on the API configuration page in the PTS console and then select By UTF-8 or By GBK for decoding.
raw
Text (text/plain): plain text in the TEXT, XML, or HTML format.
JSON (application/json): JSON string.
JavaScript (application/javascript): JavaScript string.
XML (application/xml): XML strings. Media type: application/XML
XML (text/html): XML strings. Media type: text/xml
HTML (text/html): HTML string.
Custom
The multipart, video, or image format is not supported.
Examples
For example, after a book system is first launched, you can access the system by using the initial account (name=test, password=123456). To perform stress testing on the system, you must define a body to specify a stress testing request. The following examples show how to define a body:
x-www-form-urlencoded format
The following figure shows how to define the body in the key-value pair format.
Click Text Format in the upper right corner of the Body Definition tab to transfer the key-value pair format into the text format. You can enter up to 65,535 characters. Example:
{"name":"test","password":"123456"}
JSON(application/json) format
{"code":200,"data":{"items":[{"id":"123","name":"yaozhuang"},{"id":"456","name":"fuzhuang"}]},"requestId":"Cf2HJKEf-197B-JK47-79E9-FA*****4KA40","successResponse":false}
Text(text/plain) format
<?xml version="1.0"?><resource><id>123</id><params><name><value>test</value></name></params></resource>