當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript http.get函數代碼示例

本文整理匯總了TypeScript中k6/http.get函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript get函數的具體用法?TypeScript get怎麽用?TypeScript get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了get函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: test3

function test3() {
    const res = http.get("http://httpbin.org");
    check(res, {
        "response code was 200": (res) => res.status === 200,
        "body size was 1234 bytes": (res) => res.body.length === 1234,
    });
}
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:7,代碼來源:k6-tests.ts

示例2: group

 group("features page", () => {
   const res = http.get("https://loadimpact.com/features");
   check(res, {
     "status code is 200": (res) => res.status === 200,
     "h1 message is correct": (res) => res.html("h1").text().startsWith("Simple yet realistic load testing"),
   });
 });
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:7,代碼來源:k6-tests.ts

示例3: httpTest10

function httpTest10() {
    // Request page with links
    let res = http.get("https://httpbin.org/links/10/0");

    // Now, click the 4th link on the page
    res = res.clickLink({ selector: 'a:nth-child(4)' });
}
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:7,代碼來源:k6-tests.ts

示例4: httpTest11

function httpTest11() {
    // Request page containing a form
    let res = http.get("https://httpbin.org/forms/post");

    // Now, submit form setting/overriding some fields of the form
    res = res.submitForm({ fields: { custname: "test", extradata: "test2" }, submitSelector: "mySubmit" });
}
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:7,代碼來源:k6-tests.ts

示例5: httpTest5

function httpTest5() {
    const options = { maxRedirects: 10 };

    const baseURL = "https://dev-li-david.pantheonsite.io";

    // Fetch the login page, with the login HTML form
    const res1 = http.get(baseURL + "/user/login");

    // Extract hidden value needed to POST form
    const formBuildID = (res1.body.match('name="form_build_id" value="(.*)"') || [])[1];
    // Create an Object containing the form data
    const formdata = {
        name: "testuser1",
        pass: "testuser1",
        form_build_id: formBuildID,
        form_id: "user_login",
        op: "Log in",
    };
    const headers = { "Content-Type": "application/x-www-form-urlencoded" };
    // Send login request
    const res2 = http.post(baseURL + "/user/login", formdata, { headers });
    // Verify that we ended up on the user page
    check(res2, {
        "login succeeded": (res2) => res2.url === `${baseURL}/users/testuser1`,
    }) || fail("login failed");
}
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:26,代碼來源:k6-tests.ts

示例6: httpTest6

function httpTest6() {
	const params = {
        cookies: { my_cookie: "value" },
        headers: { "X-MyHeader": "k6test" },
        redirects: 5,
		tags: { k6test: "yes" }
	};
    http.get("https://loadimpact.com", params);
}
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:9,代碼來源:k6-tests.ts

示例7: httpTest8

function httpTest8() {
    // Passing username and password as part of URL plus the auth option will authenticate using HTTP Digest authentication
    const res = http.get("http://user:passwd@httpbin.org/digest-auth/auth/user/passwd", {auth: "digest"});

    // Verify response
    check(res, {
        "status is 200": (r) => r.status === 200,
        "is authenticated": (r) => r.json().authenticated === true,
        "is correct user": (r) => r.json().user === "user"
    });
}
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:11,代碼來源:k6-tests.ts

示例8: httpTest9

function httpTest9() {
	const res = http.get("https://loadimpact.com");
	for (const p in res.headers) {
		if (res.headers.hasOwnProperty(p)) {
			console.log(`${p} : ${res.headers[p]}`);
		}
	}
  check(res, {
    "status is 200": (r) => r.status === 200,
    "caption is correct": (r) => r.html("h1").text() === "Example Domain",
  });
}
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:12,代碼來源:k6-tests.ts

示例9: test6

function test6() {
    http.get("https://loadimpact.com");
    sleep(Math.random() * 30);
    http.get("https://loadimpact.com/features");
}
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:5,代碼來源:k6-tests.ts


注:本文中的k6/http.get函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。