GetDatas.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net;
  6. using System.IO;
  7. using System.Xml;
  8. namespace CB.Common
  9. {
  10. public static class GetDatas
  11. {
  12. public static string GetNewsData(long qi, int cid, int size)
  13. {
  14. string newinfos = GetNews(qi, cid, size);
  15. if (string.IsNullOrEmpty(newinfos))
  16. {
  17. return "";
  18. }
  19. string news="";
  20. string[] infos = newinfos.Split('|');
  21. if (infos.Length > 0 && infos != null)
  22. {
  23. for (int i = 0; i < infos.Length - 1; i++)
  24. {
  25. string[] s = infos[i].Split('&');
  26. DateTime time = Convert.ToDateTime(s[2]);
  27. 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>";
  28. }
  29. }
  30. return news;
  31. }
  32. public static string GetNews(long qi,int cid,int size)
  33. {
  34. HttpWebResponse HttpWResp = null;
  35. HttpWebRequest myReq = null;
  36. StringBuilder sb = new StringBuilder();
  37. Stream myStream = null;
  38. StreamReader sr = null;
  39. Encoding code = Encoding.GetEncoding("gb2312");
  40. try
  41. {
  42. string path = AppDomain.CurrentDomain.BaseDirectory + "Config\\url.xml";
  43. XmlDocument xml = new XmlDocument();
  44. xml.Load(path);
  45. XmlNode root = xml.SelectSingleNode("path");
  46. string url = root.InnerText.Trim();
  47. url += "?Typename=select";
  48. string paras=string.Format("topSize={0}|cid={1}|qi={2}",size,cid,qi);
  49. string sign=Utils.MD5("d3d3LjNkdGFpaHV6aW1pLmNu"+"select"+paras);
  50. url = url + "&paras=" + paras + "&sign=" + sign;
  51. myReq = (HttpWebRequest)WebRequest.Create(url);
  52. myReq.Timeout = 5000;
  53. myReq.ContentType = "text/html;charset=gb2312";
  54. myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
  55. HttpWResp = (HttpWebResponse)myReq.GetResponse();
  56. myStream = HttpWResp.GetResponseStream();
  57. sr = new StreamReader(myStream, Encoding.UTF8);
  58. sb.Append(sr.ReadToEnd());
  59. return sb.ToString();
  60. }
  61. catch(Exception)
  62. {
  63. return "";
  64. }
  65. }
  66. }
  67. }