I'm currently trying to send a post request with PHP with duplicated parameter, here's what I have done so far.
$searchData = array(
'ListShow' => 'ListShow',
'dspSsuPd' => '200', //rows per page
// 'szkbuChkbx' => json_encode($arrsearhchbx),
'szkbuChkbx[]' => array('011',
'012',
'111',
'112'),
'lstDspPg' => $n //pages
);
$searchData = http_build_query($searchData);
//search with cookie and data to get result
if ($cookie == '') {
echo 'cookie is empty';
} else {
// echo $cookie . "\n";
$searchResult = postRequest($searchActionURL, $cookie, $searchData);
// echo ($searchResult);
The postRequest function:
function postRequest($url, $cookie, $params)
{
//echo $cookie;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded",
"postman-token: 2c3803ce-d9e9-d7b5-4ba6-cb0313cd1e22",
"user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
"Cookie: " . $cookie,
),
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
return false;
} else {
return $response;
}
}
I have referred to the manual and they did say that CURLOPT_POSTFIELDS don't mix well with curl_setopt_array() so I used curl_setopt() for that specific option to no avail. There is also a post that talked about this: How do I use arrays in cURL POST requests I tried following but it still doesn't work and only send the last element of szkbuChkbx. Anyone have any idea how can I achieve this?