1 private void callApibjhb()
2 {
3 //输出执行的开始时间
4 Console.WriteLine(string.Format("Bind {0}", DateTime.Now));
5 Thread T = new Thread(() =>
6 { //表示不停刷新,如果不需要可以删除
7 while (true) {
8
9 string strURL = "";
10 try
11 {
12 System.GC.Collect();
13 string strURL =“你请求的网址”;
14 System.Net.HttpWebRequest request;
15 // 创建一个HTTP请求
16 request = (System.Net.HttpWebRequest)WebRequest.Create(strURL);
17 request.Method = "GET";
18 request.Timeout = 600000;
19 request.ContentType = "application/json;charset=UTF-8";
20 request.ServicePoint.Expect100Continue = false;
21 request.KeepAlive = false;
22 System.Net.ServicePointManager.DefaultConnectionLimit = 50;
23 System.Net.HttpWebResponse response;
24 response = (System.Net.HttpWebResponse)request.GetResponse();
25 Stream myResponseStream = response.GetResponseStream();
26 StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
27 string retString = myStreamReader.ReadToEnd();
28 Console.WriteLine("ret string === {0}+ {1}", retString, strURL);
29 //创建RepParambj28hb类,字段格式是:根据“请求网站返回的Json字符串”,到网上搜“在线Json格式化”去解析
30 RepParambj28hb rep = JsonConvert.DeserializeObject<RepParambj28hb>(retString);
31 for (int i = 0; i < rep.result.lotterys.Length; i++)
32 {
33 //根据自己的需求,得到值
34 string jh = rep.result.lotterys[i].opencode.Replace(",", "");
35 dt.Rows[dt.Rows.Count - 1]["cl1"] = rep.result.lotterys[i].expect;
36 }
37 myStreamReader.Close();
38 myResponseStream.Close();
39
40 }
41 catch (Exception webEx)
42 {
43 }
44 }
45 });
46
47 T.Start();
48 Console.WriteLine(string.Format("Bind end {0}", DateTime.Now));
49 }