nav-img
Advanced

Adding Request Information (Packet)

Packets are data blocks transmitted between HTTP-, HTTPS-, TCP-, and UDP-based applications. These data blocks start with text metadata that describes the packet content and meaning. The text metadata is followed by optional data. Packets are transmitted among clients, servers, and agents.

Procedure

  1. Log in to the CPTS console and choose CPTS Test Projects in the navigation pane on the left.
  2. Locate a CPTS test project to be edited and click Edit Test Task.
  3. On the Test Tasks tab page, expand a task, expand the test case to which you want to add request information, and click Add Request.
  4. Select Packet for Request Composition and set the other parameters by referring to Table 1.

    Table 1 Packet parameters

    Parameter

    Description

    Protocol Type

    Select a protocol used by your service.

    When Protocol Type is HTTP or HTTPS, set the following parameters.

    Request Mode

    GET, POST, PATCH, PUT, and DELETE

    Response Timeout (ms)

    Indicates the timeout period for waiting for a response from the server when a request is sent.

    The default response timeout duration is 5000 ms.

    Variables can be inserted. For details, see Inserting a Variable.

    NOTE:

    Restrictions on variables are as follows:

    1. The variable type must be Enumerated.
    2. Only one value (a numeric string) is allowed in each variable.
    3. The value ranges from 20 ms to 60s.

    Carried cookie

    NOTE:

    At least one request exists in the case. Set parameters when adding new requests.

    • Obtain automatically: Use the cookie set in the response.
    • Obtain manually: Use the cookie in the header of the current request.

    Request URL

    Indicates the URL for sending a request, for example, http://domain name/path, or http://domain name/path?key1=value1&key2=value2.

    Variables can be inserted. For details, see Inserting a Variable.

    Request Parameter

    Set the parameters in the request URL.

    Click Add Request Parameter and set Key and Value. If you do not need to add request parameters, click Delete to delete the request parameters.

    Headers

    Add headers and contents based on the headers to be verified or used by a pressure test server. Headers are not mandatory for CPTS, which only transparently transmits user-defined headers to the pressure test server. For details about Header, see Header Description.

    Click Add Header to set Header and Value. If you do not need to add header information, click Delete to delete the packet header.

    NOTE:

    If Request Mode is POST or PUT and Header is Content-Type, variables can be inserted, and Value can be one of the three following types:

    • Customize: Enter a value in the text box.
    • application/x-www-form-urlencoded: The request body is a key value pair that can be added. The value is text.
    • multipart/form-data: The request body is a key-value pair that can be added. The value can be text or a file. If the value is a file, the body can be imported.

    Body

    The body of an entity contains a data block consisting of random data. Not all packets contain the body of an entity. Sometimes, a packet ends with only CRLF.

    If global variables have been set or local variables have been set for the response extraction, variables can be used in the packet content. During a pressure test, variables in the packet content will be replaced with specified values.

    1. Enter $ in the packet content input box.
    2. In the Insert Variable dialog box, set parameters. For details, see Inserting a Variable.
    3. Click Select.
    NOTE:

    When the Request Mode is GET, the input of packet content is not supported.

    When the Protocol Type is TCP, set the following parameters.

    IP

    Indicates the IP address of the tested server to which requests are sent.

    Port Number

    Indicates the port number of the tested server to which requests are sent.

    Connection Timeout (ms)

    Indicates the timeout duration for the server's response after a connection is initiated.

    Response Timeout (ms)

    Indicates the timeout duration for the server's response after a connection is established.

    Connection Settings

    • Repeated use: When the response is returned, the connection remains open and is used to receive the next response.
    • Close: When the response is returned, the connection is closed and a new connection needs to be established next time.

    Return Settings

    The settings are used to judge whether a request response has been received.

    • Length of returned data: The length of the returned data is set in bytes. When a response of this length is received, data receiving is complete.
    • End-of-text character: indicates the ending mark of returned data. When an end-of-text character is received, data receiving is complete.
      NOTE:

      It is recommended that a unique end-of-text character be set. If there are multiple such characters in a response, when the first character is received, the response is considered to have been received. As a result, the received response data is incomplete.

    Packet Content

    The body of an entity contains a data block consisting of random data. Not all packets contain the body of an entity. Sometimes, a packet ends with only CRLF.

    Content format: Select character strings or a hexadecimal code stream based on the service request content of the tested server.

    NOTE:

    A hexadecimal code stream can contain only numbers 0–9 and letters a–f. The total number of characters must be an even number.

    If global variables have been set or local variables have been set for the response extraction, variables can be used in the packet content. During a pressure test, variables in the packet content will be replaced with specified values.

    1. Enter $ in the packet content input box.
    2. In the Insert Variable dialog box, set parameters. For details, see Inserting a Variable.
    3. Click Select.

    When the Protocol Type is UDP, set the following parameters.

    IP

    Indicates the IP address of the tested server to which requests are sent.

    Port Number

    Indicates the port number of the tested server to which requests are sent.

    Return Settings

    The settings are used to judge whether a request response has been received.

    • Length of returned data: The length of the returned data is set in bytes. When a response of this length is received, data receiving is complete.
    • End-of-text character: indicates the ending mark of returned data. When an end-of-text character is received, data receiving is complete.
      NOTE:

      It is recommended that a unique end-of-text character be set. If there are multiple such characters in a response, when the first character is received, the response is considered to have been received. As a result, the received response data is incomplete.

    Packet Content

    The body of an entity contains a data block consisting of random data. Not all packets contain the body of an entity. Sometimes, a packet ends with only CRLF.

    Content format: Select character strings or a hexadecimal code stream based on the service request content of the tested server.

    NOTE:

    A hexadecimal code stream can contain only numbers 0–9 and letters a–f. The total number of characters must be an even number.

    If global variables have been set or local variables have been set for the response extraction, variables can be used in the packet content. During a pressure test, variables in the packet content will be replaced with specified values.

    1. Enter $ in the packet content input box.
    2. In the Insert Variable dialog box, set parameters. For details, see Inserting a Variable.
    3. Click Select.

  5. When the configuration is complete, click OK.

Filling in a Packet

The process of sending a packet is as follows: A click operation is edited to a code stream complying with protocol specifications and carrying a user's request before the code stream is sent to different third parties, leading to a correct or failed response. Press F12 or use a packet-capturing tool (such as Wireshark) to check how a packet is requested and fill in the packet to be tested according to the actual service.

For example, to simulate the POST method of a login request, the corresponding request URL, request mode, header field, and packet content are shown in the following figure.

Figure 1 Simulating logging in to a request using the POST method