• C#写一个URL编码转换GB23121的方法,然后可以取到天气预报


      /// <summary>
      /// 根据城市取得天气预报信息
      /// </summary>
      /// <param name="ps_CityName">城市中文名称 如:福州</param>
      /// <returns></returns>
      public static string GetSinaWether(string ps_CityName)
      {
       string strCity = StrConv(ps_CityName,"GB2312");
       
       //string myuri="http://appnews.qq.com/cgi-bin/news_qq_search?city="+city;
       string myuri="http://weather.news.sina.com.cn/cgi-bin/figureWeather/simpleSearch.cgi?city="+strCity;   
       WebRequest webr=WebRequest.Create(myuri);
       

       Stream rc=webr.GetResponse().GetResponseStream();
       
       StreamReader read=new StreamReader(rc,System.Text.Encoding.Default);
       string abc=read.ReadToEnd();
       int l1=abc.IndexOf("今日天气");
       string restr="<font face=黑体 style=font-size:18px;>"+abc.Substring(l1).Replace("<br>","").Replace("<td style=","").Replace("class=l15>","").Replace("color:#083887","").Replace("</td>","").Replace("</tr>","").Replace("</table>","").Replace("</body>","").Replace("</html>","");
       return restr.Replace("50","20");
      }

      /// <summary>
      /// 根据城市取得天气预报信息
      /// </summary>
      /// <param name="ps_CityName">城市中文名称 如:福州</param>
      /// <returns></returns>
      public static string GetQQWether(string ps_CityName)
      {
       string strCity = StrConv(ps_CityName,"GB2312");
       
       string myuri="http://appnews.qq.com/cgi-bin/news_qq_search?city="+strCity;
       WebRequest webr=WebRequest.Create(myuri);
       
       Stream rc=webr.GetResponse().GetResponseStream();
       
       StreamReader read=new StreamReader(rc,System.Text.Encoding.Default);
       string abc=read.ReadToEnd();
       return abc;
      }

      /// <summary>
      /// 编码转换
      /// </summary>
      /// <param name="strIn"></param>
      /// <param name="encoding"></param>
      /// <returns></returns>
      public static string StrConv(string strIn, string encoding)
      {
       return System.Web.HttpUtility.UrlEncode(strIn,System.Text.Encoding.GetEncoding(encoding));
      }

  • 相关阅读:
    人物-作家-马克·吐温:马克·吐温
    人物-发明家-特斯拉:尼古拉·特斯拉
    视觉暂留-Info:这些神奇的“视觉暂留”动画,每一幅都让人拍案叫绝!
    视觉暂留:余晖效应/视觉暂留
    mingetty
    mesg
    md5sum
    man.conf
    man
    makemap
  • 原文地址:https://www.cnblogs.com/liubiqu/p/94062.html
Copyright © 2020-2023  润新知