在https网站中使用cURL会导致很多问题

时间:2019-07-17 06:27:10

标签: php curl

在https网站中使用cURL会引起很多问题

在LAMP堆栈中,我们尝试过此操作。

 $url = "https://free.currencyconverterapi.com/api/v6/convert?q=".$from."_".$to."&compact=ultra&apiKey=73e3def35594a590f731";
$request = curl_init();
$timeOut = 10;
curl_setopt ($request, CURLOPT_URL, $url);
curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut);
    curl_setopt($request, CURLOPT_TIMEOUT, 30);
    session_write_close(); 
$response = curl_exec($request);
curl_close($request);
    session_start();
$json = json_decode($response, true);
if (is_array($json)) $rate = implode(" ",$json);
$total = $rate * $amount;
$rounded = round($total); //optional, rounds to a whole number
echo $total;

有时候,它不起作用。

0 个答案:

没有答案