【发布时间】:2019-10-09 08:36:56
【问题描述】:
我有一个像这样的 Guzzle POST 请求:
// 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!";
}
}
我的 body 变量值在打印时存在于每个循环中。但是当我在 $client->post 中使用它时,我的请求返回错误,其中包含 user_id、title、message 是必需的。我真的不知道为什么会这样?
你能告诉我我的代码有什么问题吗?
谢谢!
【问题讨论】:
-
尝试将
$body替换为[ 'form_params' => $body]! -
它仍然有这个错误,需要 3 个第一个字段。好奇怪!
-
你调用你的webservice还是第三方WS?