У меня есть запрос POST с Guzzle следующим образом:
// Return a collection
$cart = $this->getCart('2019-10-08 07:08:39');
//Return first entry of the collection with first()
$template = $this->getTemplate($config->key);
$isDetail = null;
foreach ($cart as $item) {
try {
$client = $this->getClient();
$headers = ['Content-Type' => 'application/json'];
$body = [
'user_id' => $item->mystore_user_id,
'title' => $template->title,
'message' => $template->message,
'avatar' => $template->avatar,
'detail_id' => $isDetail,
'schedule' => null
];
print_r($body);
$response = $client->post('push-noti/unicast', $headers, $body);
print_r(response()->json(json_decode($response->getBody(), true)));
} catch (QueryException | \Exception $ex) {
echo "Error!";
}
}
Мое значение переменной тела существует в каждом цикле, когда оно напечатано. Но когда я использую его в $client->post, мой запрос возвращает ошибку с user_id, title, message. Я действительно не знаю, почему это?
Можете ли вы сказать мне, что не так в моем коде?
Благодарю вас!
$body
на[ 'form_params' => $body]
! - person Maraboc   schedule 09.10.2019