I'm trying to use Guzzle to make a request from my server, not a requirement. I use cURL and that works, however when I try with Guzzle I get a 403 error saying the client rejected my request which makes me believe the params are not being passed correctly.
This is my cURL code:
// Sending Sms
$url = "https://api.xxxxxx.com/v3/messages/send";
$from = "xxxxxx";
$to = $message->getTo();
$client_id = "xxxxxx";
$client_secret = "xxxxxx";
$query_string = "?From=".$from."&To=".$to."&Content=".$content."&ClientId=".$client_id."&ClientSecret=".$client_secret."&RegisteredDelivery=true";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.$query_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
curl_close ($ch);
This is my Guzzle code now:
$client = new Client();
$response = $client->request('GET', "https://api.xxxxxx.com/v3/messages/send", [
"From" => "xxxxxx",
"To" => $message->getTo(),
"Content" => $content,
"ClientId" => "xxxxxx",
"ClientSecret" => "xxxxxx",
"RegisteredDelivery" => "true"
]);
From the documentation:
You can specify the query string parameters using the
queryrequest option as an array.$client->request('GET', 'http://httpbin.org', [ 'query' => ['foo' => 'bar'] ]);
So just make your array multidimensional, placing your query string parameters in the query element of the array.
$client = new Client();
$response = $client->request('GET', "https://api.xxxxxx.com/v3/messages/send", [
"query" => [
"From" => "xxxxxx",
"To" => $message->getTo(),
"Content" => $content,
"ClientId" => "xxxxxx",
"ClientSecret" => "xxxxxx",
"RegisteredDelivery" => "true",
],
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With