且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Guzzle以JSON发送POST请求?

更新时间:2023-01-17 08:31:22

对于枪口< = 4 :

这是一个原始的发布请求,因此将JSON放在正文中即可解决问题

It's a raw post request so putting the JSON in the body solved the problem

$request = $this->client->post($url,array(
                'content-type' => 'application/json'
        ),array());
$request->setBody($data); #set body!
$response = $request->send();

return $response;