【发布时间】:2018-11-16 03:13:58
【问题描述】:
我正在尝试使用 Guzzle 从我的服务器发出请求,而不是要求。我使用 cURL 并且有效,但是当我尝试使用 Guzzle 时,我收到一个 403 错误,说客户端拒绝了我的请求,这让我相信参数没有正确传递。
这是我的 cURL 代码:
// 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);
这是我现在的 Guzzle 代码:
$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"
]);
【问题讨论】: