0

I have 3 arrays to be passed to the variables of a URL. I'll like to know how to pass them to the URL.

export default function () {
    let p_code = ['P', 'Y', 'M', 'C'];
  let c_flg = ['O', 'C', 'B'];
  let page = ['H', 'F', 'W'];
    let res = "";

    for (var i = 0; i < p_code.length; i++) {
        res = http.post('https://myabcdomain.com/pass/mark/myhope.jsp?p_code='+p_code[i]+'&set_id=999&crncy_code=NGN&cls_opn_flg='+c_flg[i]+'&high_tran_date_ui='+encodeURIComponent('2021-01-04T05')+'&page_size='+page[i], {
      tags: { name: 'UISheetPrint' },
    });
      // console.log(accountNumbers[i]);
  }
}
halfer
  • 19,824
  • 17
  • 99
  • 186
ken4ward
  • 2,246
  • 5
  • 49
  • 89
  • 1
    a) Do you have any control on the receiving side? so both client and server can agree on a format. b) if you're already using post, Have you considered passing this in the body? – malarres Mar 02 '21 at 15:54
  • Does this answer your question? [How to pass an array as a URL parameter?](https://stackoverflow.com/questions/40493085/how-to-pass-an-array-as-a-url-parameter) – Renat Mar 02 '21 at 16:01
  • @Renat, thanks. That's just for a parameter. I need to pass to 3 variables – ken4ward Mar 02 '21 at 16:04
  • @malarres, nope. I'm running a load test, and I don't have access to the server only the URL link – ken4ward Mar 02 '21 at 16:05

1 Answers1

0

Elaborating on @Renat comment, and following https://stackoverflow.com/a/40493291/2729605, you can do:

  let p_code = ['P', 'Y', 'M', 'C'];
  let c_flg = ['O', 'C', 'B'];
  let page = ['H', 'F', 'W'];
  let res = "";
  let p_codeStr = encodeURIComponent(JSON.stringify(p_code));
  let c_flgStr  = encodeURIComponent(JSON.stringify(c_flg));
  let pageStr  = encodeURIComponent(JSON.stringify(page));

  let reqStr = `https://myabcdomain.com/pass/mark/myhope.jsp?p_code=${p_codeStr}&set_id=999&crncy_code=NGN&cls_opn_flg=${c_flgStr}&high_tran_date_ui=${encodeURIComponent('2021-01-04T05')}&page_size=${pageStr}`

console.log(reqStr)


// res = http.post(reqStr, {
//      tags: { name: 'UISheetPrint' },
//    });

(uncomment the post)

malarres
  • 2,941
  • 1
  • 21
  • 35