直接在浏览器中使用时收到的JSON数据,但不包含cURL

时间:2017-11-06 07:28:28

标签: php json curl

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'https://www.unocoin.com/trade?all');
$result = curl_exec($ch);
curl_close($ch);
$data = json_decode($result);
return $data;

直接在浏览器中使用时会收到JSON数据,但不会在PHP中使用cURL。

1 个答案:

答案 0 :(得分:1)

试试这个,

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://www.unocoin.com/trade?all=",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET"
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

回应:

{
    "buy": 505189,
    "sell": 487508,
    "avg": 496348
}