I intend to use the api for a link shortening service, the api address for this site is as follows:
http://mitly.ir/api.php
And for example for this request:
http://mitly.ir/api.php?url=https://google.com
This outputs json:
{
"longurl": "https:\/\/google.com",
"shorturl": "http:\/\/mitly.ir\/12MxP",
"stats": "http:\/\/mitly.ir\/stats.php?id=12MxP"
}
Now I wrote the following code to use this api, but unfortunately the output that returns to me is null:
//API Url
$url = 'http://mitly.ir/api.php';
//Initiate cURL.
$ch = curl_init($url);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "url=https://google.com");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
//Execute the request
$result = curl_exec($ch);
//echo $result;
$response = json_decode($result, true);
var_dump($response);
echo "your url is :".$response['result']['shorturl'];
Please help me solve this problem