PHP cURL not allowed multidimentional array

Assalamu’alaikum warahmatullah wabarakatuh

In this case, I running on project at work, build the main portal project. The portal should use so many database from any host. We can’t build it ini one big systems, it’s not good for maintenance and the source sistem is available before.

My department made Rest Api’s system to control the data. Using PHP, and the most popular framework for systems and plugins it was developed.

Today I get some trouble when I post the data to rest server. I was test it in Postman, and work correctly. But, when I try to send the data using PHP cURL, it’s not work.

Here the solution

My friends told me to encode the data as json data before posting. And, well, it’s work. I use system helper and rest plugin, so not using self code to build rest. In my system helper, I found errror at:

curl_setopt($ch, CURLOPT_POSTFIELDS, $data['post'] );

The $data[] is not allowing multidimentional array. As you know, the array just fill by field. And the sub array was nulled. When I encode the $data before post, I have the result as json data and the multidimetional array is work correctly.

{"pegawai_id":"401","nama":"Suprapti","hubungan":"istri","no_kartu":"8687687687","tmp_lahir":"Magelang","tgl_lahir":"1995-02-20","tgl_nikah":"2017-02-20","keterangan":"kjkjkjk","pendidikan":"6","is_meninggal":"1","no_npwp":"8678687","id_lain":"42424234","pekerjaan":"Mahasiiswa","hub_mertua":["Ayah","Ibu"],"nama_mertua":["suprapto","Suprapti ibunya"]}

Just a little notes for my future.

Wassalamu’alaikum warahmatullah

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments

Would love your thoughts, please comment.x