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}}
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/17479765.html