123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Net;
- using System.IO;
- using System.Xml;
- namespace CB.Common
- {
- public static class GetDatas
- {
- public static string GetNewsData(long qi, int cid, int size)
- {
- string newinfos = GetNews(qi, cid, size);
- if (string.IsNullOrEmpty(newinfos))
- {
- return "";
- }
- string news="";
- string[] infos = newinfos.Split('|');
- if (infos.Length > 0 && infos != null)
- {
- for (int i = 0; i < infos.Length - 1; i++)
- {
- string[] s = infos[i].Split('&');
- DateTime time = Convert.ToDateTime(s[2]);
- news += "<li><a href=\"" + infos[infos.Count() - 1] + time.ToString("yyyyMMdd") + "_" + s[0] + ".htm\" target=\"_blank\">" + Utils.GetLoadTitle(s[1]) + "</a><span class=\"time\">" + time.ToString("MM-dd") + "</span></li>";
- }
- }
- return news;
- }
- public static string GetNews(long qi,int cid,int size)
- {
- HttpWebResponse HttpWResp = null;
- HttpWebRequest myReq = null;
- StringBuilder sb = new StringBuilder();
- Stream myStream = null;
- StreamReader sr = null;
- Encoding code = Encoding.GetEncoding("gb2312");
- try
- {
- string path = AppDomain.CurrentDomain.BaseDirectory + "Config\\url.xml";
- XmlDocument xml = new XmlDocument();
- xml.Load(path);
- XmlNode root = xml.SelectSingleNode("path");
- string url = root.InnerText.Trim();
- url += "?Typename=select";
- string paras=string.Format("topSize={0}|cid={1}|qi={2}",size,cid,qi);
- string sign=Utils.MD5("d3d3LjNkdGFpaHV6aW1pLmNu"+"select"+paras);
- url = url + "¶s=" + paras + "&sign=" + sign;
- myReq = (HttpWebRequest)WebRequest.Create(url);
- myReq.Timeout = 5000;
- myReq.ContentType = "text/html;charset=gb2312";
- myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
- HttpWResp = (HttpWebResponse)myReq.GetResponse();
- myStream = HttpWResp.GetResponseStream();
- sr = new StreamReader(myStream, Encoding.UTF8);
- sb.Append(sr.ReadToEnd());
- return sb.ToString();
- }
- catch(Exception)
- {
- return "";
- }
- }
- }
- }
|