这是postman的脚本,记录了:
- 存储返回的数据
- 刷新请求的cookie
具体操作:
- 存储返回的数据
var jsonData = JSON.parse( responseBody );
postman.setEnvironmentVariable( "oa_access_token", jsonData.access_token );
postman.setEnvironmentVariable( "oa_refresh_token", jsonData.refresh_token );
tests["Status code is 200"] = responseCode.code === 200;
- 刷新请求的cookie,未校验,很可能有错
pm.globals.unset("cookie"); // 清除指定的全局变量
pm.setGlobalVariable('cookie', value);
function delCookie(name) {
var cval = getCookie(name);
if (cval !== null){
var exp = new Date();
exp.setTime(exp.getTime() - 1);
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
delCookie("account_token");
delCookie("stuapp_token");