我最近將我的 guzzle 版本從 3 更新到 6。以下調(diào)用在 3 上工作,但現(xiàn)在我需要將其升級到 6(因為它不工作)。閱讀文檔后,我有點困惑這個新的帖子請求在 Guzzle 6 中是如何工作的。這是我在 Guzzle 3 中的舊帖子請求 try { $request = $this->guzzleClient->post( '/login?token='.$this->container->getParameter("token"), array(), json_encode($data) ); $request->setHeader('Content-Type', 'application/json'); $response = $request->send(); return $response->json(); }我如何翻譯它以便發(fā)布請求?
1 回答

一只萌萌小番薯
TA貢獻1795條經(jīng)驗 獲得超7個贊
你需要這個:
$response = $this->guzzle6->post(
'/login?token='.$this->container->getParameter("token"),
[
'json' => $data
]
);
return json_decode($response->getBody()->getContents());
Guzzle 6 沒有->json()響應(yīng),所以你必須自己解碼。
- 1 回答
- 0 關(guān)注
- 139 瀏覽
添加回答
舉報
0/150
提交
取消