2022年1月21日以来,新浪股票接口更新后,原来的http://hq.sinajs.cn/list=sh600519接口访问返回403,直接网页访问返回提示“Kinsoku jikou desu!”(2022年11月份返回"Forbidden")
新浪股票的接口变动,需要在请求头中添加Referer值。
-
- $url = "http://hq.sinajs.cn/list=sh600519";
-
- $ch = curl_init();
-
- curl_setopt($ch, CURLOPT_URL, $url);
-
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-
- curl_setopt($ch, CURLOPT_REFERER, 'https://finance.sina.com.cn/');
-
- $output = curl_exec($ch);
-
- $outputUtf8 = iconv('gb2312', 'utf-8', $output);
-
- curl_close($ch);
-
- echo $outputUtf8;
-
- ?>
参考:
https://blog.csdn.net/weixin_39962125/article/details/116084696
https://blog.csdn.net/qq_45762148/article/details/123318800
https://blog.csdn.net/sunshineGGB/article/details/122983317
https://blog.csdn.net/qq1130169218/article/details/122809393