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]);
  }
}
4
  • 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? Commented Mar 2, 2021 at 15:54
  • Does this answer your question? How to pass an array as a URL parameter? Commented Mar 2, 2021 at 16:01
  • @Renat, thanks. That's just for a parameter. I need to pass to 3 variables Commented Mar 2, 2021 at 16:04
  • @malarres, nope. I'm running a load test, and I don't have access to the server only the URL link Commented Mar 2, 2021 at 16:05

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.