PHP cURL vs file_get_contents
2022-08-30 07:17:44
访问 REST API 时,这两段代码有何不同?
$result = file_get_contents('http://api.bitly.com/v3/shorten?login=user&apiKey=key&longUrl=url');
和
$ch = curl_init('http://api.bitly.com/v3/shorten?login=user&apiKey=key&longUrl=url');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
它们都产生相同的结果,判断
print_r(json_decode($result))