laravel中使用Ixudra\Curl发送数据
2018-08-17 本文已影响0人
不看盛景不叙深情
-
注释:Ixudra\Curl的安装请参考Ixudra\Curl官网
-
使用curl 发送post请求
$curl = \Curl::to($url)->to($url)
->asJsonRequest()
->withData([
'center_ip' => $center_ip,
'machine_code' => $hcode,
'action' => $action,
'node_uuid' => $nodeUuid
])
->withTimeout(60)
->asJsonResponse()
->returnResponseObject();
$res = $curl->post();
-
通过curl 使用SSL证书进行通信
$certfile = 'client.crt';
$keyfile= 'client.key';
$curl = \Curl::to('https://'.$url)
->withOption('SSL_VERIFYHOST', false)
->withOption('SSLKEY', $keyfile)
->withOption('SSLCERT', $certfile);
$res = $curl->post();
return in_array($res->status, [200, 201, 204]);