testCode
testCode

Reputation: 117

How to transform api curl code to guzzlehttp

I want to transform this curl code to use in guzzlehttp with laravel.

But I'm having problems the sent matrix doesn't seem to be working.

$url = "https://restapi.bulksmsonline.com/rest/api/v1/sms/send";

CURLOPT_RETURNTRANSFER => true,
 CURLOPT_ENCODING => "",
 CURLOPT_MAXREDIRS => 10,
 CURLOPT_TIMEOUT => 30,
 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
 CURLOPT_CUSTOMREQUEST => "POST",
 CURLOPT_POSTFIELDS => "{\"from\":\"Sender
Name\",\"to\":[\"16813000014\",\"16813000014\"],\"type\":\"Text\",\"content\":\"Sample SMS Content To Be Sent\"}",
 CURLOPT_HTTPHEADER => array(
 "token : $token",
"content-type: application/json"
 ),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
 echo "cURL Error #:" . $err;
} else {
 echo $response;
}

Upvotes: 0

Views: 35

Answers (1)

Andy Song
Andy Song

Reputation: 4684

This should work.

use Illuminate\Support\Facades\Http;

$response = Http::withHeaders([
    "token" => $token,
])->post($url,[
    "content" => "Sample SMS Content To Be Sent",
    "from" => "Sender Name",
    "to" => ["16813000014", "16813000014"],
    "type" => "Text",
]);

Upvotes: 1

Related Questions