idea http client 设置脚本

### Check response status, headers, and content-type
GET https://httpbin.org/get

> {%
    client.test("Request executed successfully", function() {
        client.assert(response.status === 200, "Response status is not 200");

    });

    client.test("Headers option exists", function() {
        client.assert(response.body.hasOwnProperty("headers"), "Cannot find 'headers' option in response");
    });

    client.test("Response content-type is json", function() {
        client.log(6666)
        var type = response.contentType.mimeType;
        client.assert(type === "application/json", "Expected 'application/json' but received '" + type + "'");
    });
%}

#####
POST https://httpbin.org/post
Content-Type: application/json

{
    "token": "my-secret-token"
}

##### 设置环境变量
> {%
    client.global.set("auth_token", response.body.json.token);
%}

##### 使用上面定义的变量
GET https://httpbin.org/headers
Authorization: Bearer {{auth_token}}
Content-Type: application/json

{
    "token": "my-secret-token"
}

##### 设置环境变量
> {%
    client.global.set("auth_token", response.body.json.token);
%}


##### 使用上面定义的变量
GET https://httpbin.org/headers
Authorization: Bearer {{auth_token}}
posted @ 2023-06-14 11:34  vx_guanchaoguo0  阅读(147)  评论(0编辑  收藏  举报