0


Postman在请求体中添加注释

GlobalJsonMinify

在Postman的Pre-request Script(前置脚本)中放入下放代码,就可以在请求体中添加注释

//  去除json参数注释方法GlobalJsonMinify=function(json){var tokenizer =/"|(\/\*)|(\*\/)|(\/\/)|\n|\r|\[|]/g,
        in_string =false,
        in_multiline_comment =false,
        in_singleline_comment =false,
        tmp, tmp2, new_str =[], ns =0, from =0, lc, rc,
        prevFrom
    ;

    tokenizer.lastIndex =0;while(tmp = tokenizer.exec(json)){
        lc = RegExp.leftContext;
        rc = RegExp.rightContext;if(!in_multiline_comment &&!in_singleline_comment){
            tmp2 = lc.substring(from);if(!in_string){
                tmp2 = tmp2.replace(/(\n|\r|\s)*/g,"");}
            new_str[ns++]= tmp2;}
        prevFrom = from;
        from = tokenizer.lastIndex;// found a " character, and we're not currently in// a comment? check for previous `\` escaping immediately// leftward adjacent to this matchif(tmp[0]==="\""&&!in_multiline_comment &&!in_singleline_comment){// limit left-context matching to only go back// to the position of the last token match//// see: https://github.com/getify/JSON.minify/issues/64
            lc.lastIndex = prevFrom;// perform leftward adjacent escaping match
            tmp2 = lc.match(/(\\)*$/);// start of string with ", or unescaped " character found to end string?if(!in_string ||!tmp2 ||(tmp2[0].length %2)===0){
                in_string =!in_string;}
            from--;// include " character in next catch
            rc = json.substring(from);}elseif(tmp[0]==="/*"&&!in_string &&!in_multiline_comment &&!in_singleline_comment){
            in_multiline_comment =true;}elseif(tmp[0]==="*/"&&!in_string && in_multiline_comment &&!in_singleline_comment){
            in_multiline_comment =false;}elseif(tmp[0]==="//"&&!in_string &&!in_multiline_comment &&!in_singleline_comment){
            in_singleline_comment =true;}elseif((tmp[0]==="\n"|| tmp[0]==="\r")&&!in_string &&!in_multiline_comment && in_singleline_comment){
            in_singleline_comment =false;}elseif(!in_multiline_comment &&!in_singleline_comment &&!(/\n|\r|\s/.test(tmp[0]))){
            new_str[ns++]= tmp[0];}}
    new_str[ns++]= rc;return new_str.join("");};

pm.request.body.raw =GlobalJsonMinify(pm.request.body.raw)//-----------------------------------------------------------------
标签: postman 测试工具

本文转载自: https://blog.csdn.net/zixiao_love/article/details/129478306
版权归原作者 itzixiao 所有, 如有侵权,请联系我们删除。

“Postman在请求体中添加注释”的评论:

还没有评论