Field | Type | Description |
basicAuth? | BasicAuth | Basic authentication. |
body? | string, object, or ArrayBuffer. | The request body to be sent, which only needs to be specified when using the http.do method. |
chunked? | function,(body string) => void | When data is sent in a series of chunks, if the chunked function is specified, the response body will be read line by line and the callback function will be executed. |
contentLength? | number | Record the length of the associated content; -1 indicates unknown length, >=0 indicates the number of bytes that can be read from the body. |
discardResponseBody? | boolean | Discard the response body, suitable for scenarios where the response body is too large and the response body content does not need to be checked. |
headers? | Record<string, string> | Request header. |
host? | string | host or host:port. |
maxRedirects? | number | The maximum number of redirects. |
method? | string | Specify the HTTP method, such as GET, PUT, and POST. It only needs to be specified when using the http.do method. |
path? | string | The path; leading slashes are omitted for relative paths. |
query? | Record<string, string> | URL parameters sent with the request. |
scheme? | "http" | "https" | Protocol, "http" or "https" should be filled in. |
service? | string | In PTS, different services are identified based on the URL, and reports are generated based on this dimension. For example, when the URL is http://demo.com/{id}, different IDs will be recognized as different services. By specifying the service, such requests can be categorized under the same service in the report. |
timeout? | number | The time limit for requests issued by the client, where the timeout period in milliseconds includes connection time, any redirects, and reading the response body. |
url? | string | The URL to be accessed, which only needs to be specified when using the do method. |
import http from 'pts/http';export default function () {const req = {method: 'post',url: 'http://httpbin.org/post',headers: { 'Content-Type': 'application/json' },query: { a: '1' },body: { user_id: '12345' },};const resp = http.do(req);console.log(resp.json().args.a); // 1console.log(resp.json().json.user_id); // 12345}