Hope you are doing really great.
I want to pass the multi-dimential as raw-data to my cURL request. But When I try to pass the array to CURLOPT_POSTFIELDS it gives me an error for Array to String Conversion.
When I am trying to pass the array like:
$post_data = [
"date"=> $_POST['date'],
"items" => $plan_details,
"form" => [
"clientName" => [
"name" => $_POST['form_data'][0]['clientName'],
"mobile" => $_POST['form_data'][0]['mobile'],
],
"clientAddress" => [
"line" => $_POST['form_data'][0]['addressLine'],
"city" => $_POST['form_data'][0]['addressCity'],
"state" => $_POST['form_data'][0]['addressState'],
"country" => "",
"pincode" => ""
],
"clientGST" => [
"companyName" => "",
"gstNo" => ""
],
]
];
And the cURL request:
curl_setopt_array($curl, array(
CURLOPT_URL => "<URL>",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $post_data,
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer <key>"
),
));
How can I pass the Multi-Dimential Array to CURLOPT_POSTFIELDS?
multipart/form-data? does it supportx-www-form-urlencoded? does it supportapplication/json?Content-Type: application/json. I have kept it inCURLOPT_HTTPHEADERand it works fine now.CURLOPT_POSTFIELDS => json_encode($post_data),for thatjson_encodethe data and then provide theContent-type.