csharp:qq weather
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Net; using System.Net.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Text; using System.IO; using System.Text.RegularExpressions; using System.Net.Cache; namespace sitemapdemo { /// <summary> /// 2011-06-16 塗聚文 /// </summary> public partial class QQweather : System.Web.UI.Page { public string selectcity = "1" ; string strUrl = "http://weather.qq.com/inc/ss1.htm" ; string old = @"<select id=""obSelect"" onchange=""getredirect(this.value)"">" ; string old1 = @"<option value=""1"">香港</option><option value=""2"">澳门</option><option value=""17"">哈尔滨</option><option value=""28"">乌鲁木齐</option><option value=""56"">西宁</option><option value=""57"">兰州</option><option value=""69"">呼和浩特</option><option value=""78"">银川</option><option value=""82"">石家庄</option><option value=""84"">太原</option><option value=""103"">长春</option><option value=""115"">沈阳</option><option selected value=""125"">北京</option><option value=""127"">天津</option><option value=""140"">济南</option><option value=""150"">拉萨</option><option value=""166"">成都</option><option value=""179"">昆明</option><option value=""186"">西安</option><option value=""189"">郑州</option><option value=""211"">武汉</option><option value=""212"">重庆</option><option value=""218"">长沙</option><option value=""227"">贵阳</option><option value=""232"">桂林</option><option value=""244"">南京</option><option value=""248"">合肥</option><option value=""252"">上海</option><option value=""255"">杭州</option><option value=""264"">南昌</option><option value=""276"">福州</option><option value=""280"">台北</option><option value=""287"">厦门</option><option value=""292"">广州</option><option value=""295"">南宁</option><option value=""296"">深圳</option><option value=""303"">海口</option>" ; string old2 = @"</select>" ; string old3 = @"市" ; string old4 = @"<img src=""/images/r_b.gif"" width=""96"" height=""21"">" ; string strWeather = string .Empty; /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load( object sender, EventArgs e) { //ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult); //HttpWebRequest req = (HttpWebRequest)WebRequest.CreateDefault(new Uri("http://intranet.lukfook.com.hk/luk_intranet/QQweather.aspx"));//https://intranet.lukfook.com.hk/luk_intranet/QQweather.aspx //req.Method = "GET"; //HttpWebResponse res = (HttpWebResponse)req.GetResponse(); //selectcity = DropDownList1.SelectedValue.ToString(); if (!IsPostBack) { this .DropDownList1.DataSource = CreateDataSource(); DropDownList1.DataTextField = "WeatherTextField" ; DropDownList1.DataValueField = "WeatherValueField" ; // Bind the data to the control. DropDownList1.DataBind(); // Set the default selected item, if desired. DropDownList1.SelectedIndex = 0; selectcity = @"1" ; strUrl = "http://weather.qq.com/inc/ss1.htm" ; strWeather = getHttpData(strUrl); strWeather = strWeather.Replace(old, "" ); strWeather = strWeather.Replace(old1, "" ); strWeather = strWeather.Replace(old2, "" ); strWeather = strWeather.Replace(old3, "" ); strWeather = strWeather.Replace(old4, "" ); geovindu.InnerHtml = strWeather; //getHttpData(strUrl); //Response.Write(s); } /* * <select id="obSelect" onchange="getredirect(this.value)"> <option value="1">香港</option><option value="2">澳门</option><option value="17">哈尔滨</option><option value="28">乌鲁木齐</option><option value="56">西宁</option><option value="57">兰州</option><option value="69">呼和浩特</option><option value="78">银川</option><option value="82">石家庄</option><option value="84">太原</option><option value="103">长春</option><option value="115">沈阳</option><option selected value="125">北京</option><option value="127">天津</option><option value="140">济南</option><option value="150">拉萨</option><option value="166">成都</option><option value="179">昆明</option><option value="186">西安</option><option value="189">郑州</option><option value="211">武汉</option><option value="212">重庆</option><option value="218">长沙</option><option value="227">贵阳</option><option value="232">桂林</option><option value="244">南京</option><option value="248">合肥</option><option value="252">上海</option><option value="255">杭州</option><option value="264">南昌</option><option value="276">福州</option><option value="280">台北</option><option value="287">厦门</option><option value="292">广州</option><option value="295">南宁</option><option value="296">深圳</option><option value="303">海口</option> */ } /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Button1_Click( object sender, EventArgs e) { //ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult); //HttpWebRequest req = (HttpWebRequest)WebRequest.CreateDefault(new Uri("http://intranet.lukfook.com.hk/luk_intranet/QQweather.aspx")); //req.Method = "GET"; //HttpWebResponse res = (HttpWebResponse)req.GetResponse(); selectcity = DropDownList1.SelectedValue.ToString(); strUrl = "http://weather.qq.com/inc/ss" +selectcity+ ".htm" ; strWeather = getHttpData(strUrl); strWeather = strWeather.Replace(old, "" ); strWeather = strWeather.Replace(old1, "" ); strWeather = strWeather.Replace(old2, "" ); strWeather = strWeather.Replace(old3, "" ); strWeather = strWeather.Replace(old4, "" ); geovindu.InnerHtml = strWeather; //getHttpData(strUrl); } /// <summary> /// <%# selectcity%> /// </summary> /// <returns></returns> ICollection CreateDataSource() { DataTable dt = new DataTable(); dt.Columns.Add( new DataColumn( "WeatherTextField" , typeof (String))); dt.Columns.Add( new DataColumn( "WeatherValueField" , typeof (String))); dt.Rows.Add(CreateRow( "香港" , "1" , dt)); dt.Rows.Add(CreateRow( "澳門" , "2" , dt)); dt.Rows.Add(CreateRow( "哈爾濱" , "17" , dt)); dt.Rows.Add(CreateRow( "烏魯木齊" , "28" , dt)); dt.Rows.Add(CreateRow( "西寧" , "56" , dt)); dt.Rows.Add(CreateRow( "蘭州" , "57" , dt)); dt.Rows.Add(CreateRow( "呼和浩特" , "69" , dt)); dt.Rows.Add(CreateRow( "銀川" , "78" , dt)); dt.Rows.Add(CreateRow( "石家莊" , "82" , dt)); dt.Rows.Add(CreateRow( "太原" , "84" , dt)); dt.Rows.Add(CreateRow( "長春 " , "103" , dt)); dt.Rows.Add(CreateRow( "瀋陽 " , "115" , dt)); dt.Rows.Add(CreateRow( "北京 " , "125" , dt)); dt.Rows.Add(CreateRow( "天津 " , "127" , dt)); dt.Rows.Add(CreateRow( "濟南 " , "140" , dt)); dt.Rows.Add(CreateRow( "拉薩 " , "150" , dt)); dt.Rows.Add(CreateRow( "成都 " , "166" , dt)); dt.Rows.Add(CreateRow( "昆明 " , "179" , dt)); dt.Rows.Add(CreateRow( "西安 " , "186" , dt)); dt.Rows.Add(CreateRow( "鄭州 " , "189" , dt)); dt.Rows.Add(CreateRow( "武漢 " , "211" , dt)); dt.Rows.Add(CreateRow( "重慶 " , "212" , dt)); dt.Rows.Add(CreateRow( "長沙 " , "218" , dt)); dt.Rows.Add(CreateRow( "貴陽 " , "227" , dt)); dt.Rows.Add(CreateRow( "桂林 " , "232" , dt)); dt.Rows.Add(CreateRow( "南京 " , "244" , dt)); dt.Rows.Add(CreateRow( "合肥 " , "248" , dt)); dt.Rows.Add(CreateRow( "上海 " , "252" , dt)); dt.Rows.Add(CreateRow( "杭州 " , "255" , dt)); dt.Rows.Add(CreateRow( "南昌 " , "264" , dt)); dt.Rows.Add(CreateRow( "福州 " , "276" , dt)); dt.Rows.Add(CreateRow( "臺北 " , "280" , dt)); dt.Rows.Add(CreateRow( "廈門 " , "287" , dt)); dt.Rows.Add(CreateRow( "廣州 " , "292" , dt)); dt.Rows.Add(CreateRow( "南寧 " , "295" , dt)); dt.Rows.Add(CreateRow( "深圳 " , "296" , dt)); dt.Rows.Add(CreateRow( "海口 " , "303" , dt)); DataView dv = new DataView(dt); return dv; } /// <summary> /// /// </summary> /// <param name="Text"></param> /// <param name="Value"></param> /// <param name="dt"></param> /// <returns></returns> DataRow CreateRow(String Text, String Value, DataTable dt) { DataRow dr = dt.NewRow(); dr[0] = Text; dr[1] = Value; return dr; } public bool CheckValidationResult( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { //直接确认,否则打不开 return true ; } /// <summary> /// /// </summary> /// <param name="url"></param> /// <returns></returns> public string getHttpData( string url) { try { //1 WebClient myWebClient = new WebClient(); //WebClient.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); Stream myStream = myWebClient.OpenRead(url); WebHeaderCollection myHeader = myWebClient.ResponseHeaders; string myCharset = myHeader.Get( "Content-Type" ); Match myMatch = Regex.Match(myCharset, "(?<=(charset=)).*$" ); StreamReader myReader = new StreamReader(myStream, Encoding.GetEncoding(myMatch.ToString())); return myReader.ReadToEnd(); } catch (System.Net.Sockets.SocketException ex) { return ex.Message.ToString(); } } /// <summary> /// /// </summary> class MyClient : WebClient { private bool tf = false ; public bool HeadOnly { get { return tf; } set { value = tf; } } protected override WebRequest GetWebRequest(Uri address) { WebRequest req = base .GetWebRequest(address); if (HeadOnly && req.Method == "GET" ) { req.Method = "HEAD" ; } return req; } } } } |
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步