### 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}}
标签:http,json,idea,token,client,#####,type,response
From: https://www.cnblogs.com/guanchaoguo/p/17479765.html