用 cookie 和数据狂欢 post

Guzzle post with cookie and data

当前的卷曲格式

curl -v --cookie "JSESSIONID=xxxxxxxxx" -X POST --data "[\"test\",\"password\"]" http://domain.com/register

如何使用 Guzzle 验证 cookie 和 post 数据?

$url = 'http://domain.com/register';
$client = new GuzzleHttp\Client();
$jar = new \GuzzleHttp\Cookie\CookieJar();
$register = $client->post($url, ['cookies' => $jar, 'http_errors' => false]);

使用 form_params 请求选项 post 数据。 使用 debug 请求选项将 Guzzle 的请求与 curl 请求进行比较。

SO 中有很多示例,Guzzle 文档解释得很好。