2024最新新浪股票接口请求方法
新浪股票接口失效解决方法,2024年访问接口出现 “Forbidden”被禁止的
解决办法是在请求头部添加Referer字段
2024 新浪股票接口更新需要加Referer才能获取数据,接口:http://hq.sinajs.cn
接口用法:http://hq.sinajs.cn?list=sh600050
Referer:http://finance.sina.com.cn
结果:
var hq_str_sh600050="中国联通, 4.780, 4.780, 4.670, 4.790, 4.650, 4.660, 4.670, 265678829, 1249341557.000, 1842619,4.660, 5982300,4.650, 3647200,4.640, 1388500,4.630, 672600,4.620, 740168,4.670, 2212046,4.680, 2134537,4.690, 2897602,4.700, 897600,4.710, 2024-03-12, 15:00:00,00,";
字段说明:
var hq_str_sh601500="
0: 通用股份 //名字;
1: 5.050 //今日开盘价
2: 5.060 //昨日收盘价
3: 5.090 //当前价格
4: 5.110 //今日最高价
5: 5.030 //今日最低价
6: 5.090 //竞买价,即“买一”报价;
7: 5.100 //竞卖价,即“卖一”报价;
8: 3963000 //成交的股票数,转手乘100
9: 20106078.000//成交金额(元),转万除10000
10: 52800 //“买一”申请52800股
11: 5.090 //“买一”报价;
12: 90600 //“买二”申请90600股
13: 5.080 //“买二”报价;
14: 98500 //..
15: 5.070 //..
16: 105200 //..
17: 5.060 //..
18: 127900 //..
19: 5.050 //..
20: 104400 //“卖一”申报104400股
21: 5.100 //“卖一”报价;
22: 99700 //“卖二”申报99700股
23: 5.110 //“卖二”报价;
24: 111800 //..
25: 5.120 //..
26: 87500 //..
27: 5.130 //..
28: 73300 //..
29: 5.140 //..
30: 2022-08-27 //日期
31: 13:18:56 //时间`
代码:
用curl请求即可,太简单了,代码不贴了,编码是GB2312的,自己转换一下
curl_setopt($ch, CURLOPT_REFERER,'http://finance.sina.com.cn');