Posted on

ubuntu中php7.0使用curl

sudo apt-get install php7.0-curl

在php中使用curl:

$url = "https://123.456.789.666:4001/login";
$header = array('Content-Type: application/json');
$data='{"password":"123456"}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
//打印獲得的數據
$output = json_decode($output);
var_dump($httpCode);
print_r($output->token);

发表评论

电子邮件地址不会被公开。