新浪股票实时数据hq.sinajs.cn突然间无法访问取不到数据,那是因为新浪股票把接口封了,在原采集数据接口里加上伪造的头部域名就可以有数据了。
$ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_REFERER, "https://finance.sina.com.cn"); //来路 curl_setopt($ch, CURLOPT_TIMEOUT, 500); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_URL, $uri); $response = curl_exec($ch); if (curl_errno($ch)) { //$errno = curl_error($ch); curl_close($ch); //return ['errno' => $errno]; return false; } else { curl_close($ch); return $response; }