美文网首页
laravel中使用Ixudra\Curl发送数据

laravel中使用Ixudra\Curl发送数据

作者: 不看盛景不叙深情 | 来源:发表于2018-08-17 17:28 被阅读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]);

相关文章

网友评论

      本文标题:laravel中使用Ixudra\Curl发送数据

      本文链接:https://www.haomeiwen.com/subject/jsstiftx.html