headerValue(name)
返回与名称匹配的标头值。名称不区分大小写。
参数 | 类型 | 描述 |
---|---|---|
name | 字符串 | 要检索值的标头名称。 |
返回值
类型 | 描述 |
---|---|
Promise<string | null> | 一个 Promise,它解析为与名称匹配的标头值,否则为 null 。 |
示例
import { browser } from 'k6/browser';
export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};
export default async function () {
const page = await browser.newPage();
try {
const res = await page.goto('https://test.k6.io/');
const headerValue = await res.headerValue('connection');
console.log(`headerValue: ${headerValue}`); // headerValue: keep-alive
} finally {
await page.close();
}
}