postman transmitting application / x-www-form-urlencoded format in the form of pre-request

 

postman in the pre-request transmission request

Knowledge points:
  • json data parsing and traversal
  • application/x-www-form-urlencoded表单
  • Basic use Array
  • js function
  • http request
  • postman global variables
Learning Path
    • postman/jquery/js document
    • blogs

demo:

// 在请求传的数据
var data = {
    test: '8888'
}


// json -- >  urlencode
function get_url_encoded_data(d){

    // urlencode存储的变量,初始值为空串
    var encode_data = "";

    // temp array
    var temp = new Array();

    // 拼接
    for(k in d){
    temp.push(k + "=" + data[k])
    }

    for (i in temp){
        if (encode_data != ""){
            encode_data = encode_data + "&" + i
        }else{
            encode_data = temp[i]
        }

    return encode_data
    }
}

var url_encode_data = get_url_encoded_data(data)

the console.log ( "url_encode_data", url_encode_data); 

const echoPostRequest = { 
  // Demo addr, addr Replace Yours 
  URL: 'www.baidu.com', 
  Method: 'the POST', 
  header: 'file application / X-WWW-form- urlencoded ', 
  dataType: "JSON", 
  body: { 
    MODE:' urlencoded ', 
    urlencoded: url_encode_data 
  } 
}; 
pm.sendRequest (echoPostRequest, function (ERR, RES) { 
  the console.log (ERR ERR: res.json ()? ); 
  // GET Person ID apos 
// pm.globals.set ( "ID", res.json () person.id). 
}); 

// after waiting for 15s request, if the content of the function, performed on the first 15s after function content (based Analyzing again, whether this use case) 
the setTimeout (function () {}, 15000);

Areas of doubt can be added (641 ... 069 ... 4..69)

Guess you like

Origin www.cnblogs.com/chenadong/p/11374718.html