Buat Variabel di PHP CurlDibuat
Login Terakhir
2 Tahun lalu,
Telah Dilihat 2050 Kali
| |
Sultan Account |
|
|
dwi vindyanto
Mengatakan :
Sultan Account
Assalamualaikum Warahmatullahi Wabarakatuh...
Minta tolong solusinya gan
Bikin variabel di sini g bisa..
Terima kasih sebelumnya
$curl = curl_init();
$username = "dingtangtong"
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://wa.domain.id/apiv1/sendText',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_POSTFIELDS =>'{
"sender":"'$username'",
"token":"zbequwdio456",
"type":"image",
"number":"628113004277",
"message":"Tess Kirim WA by API",
"url":"http://wa.domain.id/img/brosur.jpg"
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response; |
|
| PHPMU.COM Support commented on 30 Des 2022 21:43:25 Sultan Account |
|
|
|
Assalamualaikum,.. cukup tulis tanpa kutip satu atau dua, jadi seperti ini : "sender":$username, |
|
| PHPMU.COM Support commented on 30 Des 2022 21:44:09 Sultan Account |
|
|
|
atau begini harusnya juga bisa : "sender":"$username", |
|
| Dahry Dev commented on 03 Jan 2023 21:28:06 Sultan Account |
|
|
|
Waalaikumsalam. "sender":"'. $username.'", |
|
| Yusfi Cahyadi commented on 22 Feb 2023 10:44:26Free Account |
|
|
|
Assalamualaikum,..
Klo boleh saran.. lebih baik disimpan didalam array lalu convert ke json menggunakan json_encode untuk postfields-nya.
$curl = curl_init();
$username = "dingtangtong"
$postfields = array(
'sender' => $username,
'token' => 'zbequwdio456',
'type' => 'image',
'number' => '628113004277',
'message' => 'Tess Kirim WA by API',
'url' => 'http://wa.domain.id/img/brosur.jpg'
);
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://wa.domain.id/apiv1/sendText',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_POSTFIELDS => json_encode($postfields),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response; |
|