zoukankan      html  css  js  c++  java
  • 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));
      }

  • 相关阅读:
    git 常用命令
    PHP打印日志类
    如何从总账获取分类账信息
    AP -> GL 数据流动
    JDeveloper 速度慢问题
    JDeveloper 滚轮不受控制
    MyBatis 环境搭建
    初识 MyBatis
    Linux 中设置 MySQL 字符集为 UTF-8
    Linux 安装 MySQL 详解(rpm 包)
  • 原文地址:https://www.cnblogs.com/liubiqu/p/94062.html
Copyright © 2011-2022 走看看