Unanswered question

Create a dynamic POST request


I need help please.
I have this POST request:

POST /Boites/ListerOTs HTTP/1.1
Content-Type: application/json;charset=utf-8
Accept: application/json, text/plain, */*
Referer: https://mycompagny.com/#/dossiersparboites
Accept-Language: fr-FR
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: mycompagny.com
Content-Length: 18994
Connection: Keep-Alive
Cache-Control: no-cache


The body of this POST request is dynamic (it depends on a previous response). So in order to be able to replay this request, I want to create the body of this request dynamically via a javascript i.e. I want to modify my POST request to have something like this:
{"jsOTsBoite":"parameters_JSON"} where parameters_JSON is variable created by a javascript.

1- I extracted all the occurences of numeroOT and Statut and saved them in Liste_numeroOT and Liste_statut.
2- I wrote the following javascript and insert it just before my request:

// Get variables values from VariableManager
var cpt = context.variableManager.getValue("Liste_numeroOT_matchNr");
var Liste_numeroOT = context.variableManager.getValue("Liste_numeroOT");
var Liste_statut = context.variableManager.getValue("Liste_statut");
if (cpt==null) {
context.fail("Variable 'cpt' not found");
if (OTs==null) {
context.fail("Variable 'OTs' not found");
if (statutOTs==null) {
context.fail("Variable 'statutOTs' not found");

Liste_numeroOT= new array(cpt-1);
Liste_statut= new array(cpt-1);
parameters_JSON = new array(cpt-1);

for (var i = 0; i < cpt-1; i++) {
Liste_numeroOT[i] = context.variableManager.getValue("Liste_numeroOT_"+(i+1));
Liste_statut[i] = context.variableManager.getValue("Liste_statut_"+(i+1));

// Construction of a List of JSON object {\"numeroOT\":\"7101051\",\"statut\":\"BTRA\"}
parameters_JSON[i] =
numeroOT: Liste_numeroOT[i],
statut: Liste_statut[i]


// Inject the value of the parameters_JSON in a runtime variable

Lotfi B.
Lotfi B.

Lotfi B.

3 / 100


Robin L.
Robin L.

Robin L.

44 / 100

maybe using "JSON.parse" could be more usefull