Main question => How to post/write the array on a right way with NodeJs http request? (or other way)
The PHP API request array as input. Based on the example it is also need to be converted by http_build_query. The http_build_query PHP function create a following sting: “order_ids%5B0%5D=123&order_ids%5B1%5D=456&order_ids%5B2%5D=789”
$curl_parameters['order_ids'] = array(123,456,789);
$curl_options = array(
...
CURLOPT_POSTFIELDS => http_build_query($curl_parameters),
...
);
I try to do the same in NodeJs but some reason I can not send the array on a right way therefore I always got the following error message:
"
"
What I have tried:
const order_ids = { "order_ids": [123,456,789] }
const order = httpBuildQuery(order_ids)
const options = {
mehod: 'POST',
auth: username + ":" + password,
};
const req = http.request(url, options, (res) => {
res.on('data', (d) => {
process.stdout.write(d);
});
req.write(order);
req.end();
};