Slide 43
Slide 43 text
$response = self::getClient()->post('/path',
[
'form_params' => [ ... ]
,
'headers' => [ ... ]
,
])
;
$body = $response->getBody()
;
return json_decode($body, true);
$ch = curl_init()
;
curl_setopt($ch, CURLOPT_URL, 'http://
api.example.com/path')
;
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5)
;
curl_setopt($ch, CURLOPT_TIMEOUT, 5)
;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1)
;
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1)
;
curl_setopt($ch, CURLOPT_POST, 1)
;
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query([ ... ]))
;
$res = curl_exec($ch)
;
if (!curl_errno($ch))
{
$info = curl_getinfo($ch)
;
if ($info['http_code'] === 200)
{
// ...
}
}
curl_close($ch);