This is my curl code. How to write the same in Magento 2
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
if($method == 'POST') {
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Accept: application/json', 'Authorization:'.$key ));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
Please help.