What is curl in php
cURL is a library that lets you make HTTP requests in PHP.
it is a way you can hit a URL from your code to get a html response from it.
cURL means client URL which allows you to connect with other URLs and use their responses in your code
Remark:
The curl_exec command in PHP is a bridge to use curl from console.
curl_exec makes it easy to quickly and easily do GET/POST requests,
receive responses from other servers like JSON and download files.
Example:
$url = 'url_to_post';
$data = array("first_name" => "First name","last_name" => "last name","email"=>"email@gmail.
$data_string = json_encode($data);
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, array("customer"=>$data_
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Content-Type:
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
curl_close($ch);
Comments
Post a Comment