HTTP Request Configuration Option | Description |
maxRedirects | Number of redirects. |
maxIdleConns | Maximum number of active connections per VU. |
maxIdleConnsPerHost | Maximum number of active connections per VU per domain name. |
disableKeepAlives | Whether to disable persistent connection. |
headers | Common request header. |
timeout | Request timeout interval, in milliseconds. |
basicAuth | Basic authentication. |
http2 | Whether to enable HTTP/2. |
discardResponseBody | Whether to discard response packets. When the performance testing task does not focus on responses, you can enable this feature to improve testing performance. |
import http from "pts/http";export const option = {http: {timeout: 3000,}}export default function() {http.get("http://httpbin.org/get"); // Error: Get "http://httpbin.org/get": net/http: request canceled while waiting for connection}
// HTTP basic authenticationimport http from 'pts/http';import { check } from 'pts';export const option = {http: {basicAuth: {username: 'user',password: 'passwd',}}}export default function () {const resp = http.get(http://httpbin.org/basic-auth/user/passwd);console.log(resp.json().authenticated); // truecheck('body.authenticated equals true', () => resp.json().authenticated === true);}
Feedback