当前位置:网站首页>Kinsoku jikou desu新浪股票接口变动
Kinsoku jikou desu新浪股票接口变动
2022-06-23 18:49:00 【51CTO】
1、问题原因
新浪股票接口返回如标题所示值:Kinsoku jikou desu!
http://hq.sinajs.cn/list=code 新浪股票的接口变动,需要在请求头中添加Referer值。
数据源网站:新浪财经_新浪网
2、核心代码
/// <summary>
/// 获取新浪股票缓存
/// </summary>
/// <param name="args">请求查询的代码</param>
/// <returns></returns>
[
HttpGet,
HttpPost]
public
string
GetSinaStockCache(
string
args)
{
string
url
=
"http://hq.sinajs.cn/list="
+
args;
HttpWebRequest
request
= (
HttpWebRequest)
WebRequest.
Create(
url);
// 创建一个请求示例
// .NET Core版本
request.
Headers.
Add(
"Referer",
"https://finance.sina.com.cn/");
// .NET Framework版本
// request.Referer = "https://finance.sina.com.cn/";
HttpWebResponse
response
= (
HttpWebResponse)
request.
GetResponse();
// 获取响应,即发送请求
Stream
responseStream
=
response.
GetResponseStream();
StreamReader
streamReader
=
new
StreamReader(
responseStream,
Encoding.
Default);
// Default中文正常显示,UTF-8中文会乱码
string
json
=
streamReader.
ReadToEnd();
return
json;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
为了避免接口变动,可以在获取响应值时写入缓存,给缓存一个有效期,只要返回信息异常就读取缓存即可。
最后感谢新浪股票接口一直以来的稳定支持和大神的先见之明。
3、测试
请求参数(args):sz000651
返回结果:
"var hq_str_sz000651=\"格力电器,39.300,39.220,38.640,39.300,38.520,38.640,38.640,42165560,1634520898.300,465667,38.640,57333,0.000,0,0.000,0,0.000,0,0.000,465667,38.640,0,0.000,0,0.000,0,0.000,0,0.000,2022-02-17,14:59:06,00\";\n"
以上就是Kinsoku jikou desu!新浪股票接口变动的介绍,做此记录,如有帮助,欢迎点赞关注收藏!
边栏推荐
- 20set introduction and API
- Définition de la fonction et paramètres de la fonction
- LeetCode 260. 只出现一次的数字 III
- What conditions do you need to meet to fight new debts? Is it safe to fight new debts
- QGIS import WMS or WMTs
- Uniswap founder: no independent token will be issued for genie, and Genie products will be integrated into the uniswap interface
- 直播分享| 腾讯云 MongoDB 智能诊断及性能优化实践
- Helix QAC is updated to 2022.1 and will continue to provide high standard compliance coverage
- ElastricSearch第二弹之分片原理
- 每日刷题记录 (二)
猜你喜欢

不止雷军 iQOO产品经理也称赞高通骁龙8+:焕然一新

Principles of microcomputer Chapter VIII notes arrangement

How to write a great online user manual in 7 steps

LeetCode 1079. 活字印刷

LeetCode 473. 火柴拼正方形

Hardware development notes (6): basic process of hardware development, making a USB to RS232 module (5): creating USB package library and associating principle graphic devices

基于微信小程序的婚纱影楼小程序开发笔记

Leetcode daily question - 30 Concatenate substrings of all words

Définition de la fonction et paramètres de la fonction

Helix QAC is updated to 2022.1 and will continue to provide high standard compliance coverage
随机推荐
Check four WiFi encryption standards: WEP, WPA, WPA2 and WPA3
Uniswap创始人:不会为Genie发行独立代币,Genie产品将集成至Uniswap界面
Deeply understand and grasp the basic characteristics of digital economy
Advanced network accounting notes (V)
Game asset reuse: a new way to find required game assets faster
[one by one series] identityserver4 (VIII) uses entityframework core to persist data
[one by one series] identityserver4 (IV) authorization code process
【One by One系列】IdentityServer4(三)使用用户名和密码
Hardware development notes (6): basic process of hardware development, making a USB to RS232 module (5): creating USB package library and associating principle graphic devices
八大误区,逐个击破(终篇):云难以扩展、定制性差,还会让管理员失去控制权?
Advanced network planning notes (IX)
游戏资产复用:更快找到所需游戏资产的新方法
GaussDB(DWS) 数据库智能监控运维服务-节点监控指标
Matrix analysis notes (II)
String Day6 of Li Kou daily practice
[one by one series] identityserver4 (II) using client credentials to protect API resources
SAVE: 软件分析验证和测试平台
Advanced network accounting notes (VIII)
[one by one series] spa of identityserver4 (VI) authorization code process principle
Live broadcast review | detailed explanation of koordinator architecture of cloud native hybrid system (complete ppt attached)