Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHPでPOSTを投げてレスポンスからCookieを得る
<?php
require_once 'vendor/autoload.php';
use GuzzleHttp\Client;
function post($url, $data)
{
$client = new Client();
$res = $client
->post
(
$url,
[
'form_params' => $data
]
);
return $res;
}
function getCookie($res)
{
$c = explode('=', $res->getHeaders()['Set-Cookie'][0] ?? null);
$cookie = [];
if($c != null)
{
$cookie[$c[0]] = $c[1];
}
return $cookie;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.