I am trying to reverse engineer some php code and then run it in JS. The php code is as follows:
$fields_string = '';
//url-ify the data for the POST
foreach($data as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//decode result;
$data = json_decode($result, TRUE);
//close connection
curl_close($ch);
return $data;
I am using axios in JS and currently trying the following:
const response: any = await axios.post(base_url, 'key1=value1&key2=value2', {
headers: {
'Content-Type': "multipart/form-data"
}
});
But I seem to be getting issues as the server isn't able to parse the body correctly. I was wondering if anyone had any tips for what it should look like instead?