}
#endregion
private void Command1_Click(object sender, System.EventArgs e)
...{
string city = s_weather.Selection.Value.Trim();
int start,stop;
string weather1,weather2,wea;
string wea_city = weather_city(city);
wea_city = wea_city.Replace(" ","");
start = wea_city.IndexOf("<b>",0,wea_city.Length);
stop = wea_city.IndexOf("</b>", start);
weather1 = wea_city.Substring(start, stop-start).Trim() + " ";
weather1 = weather1.Substring(3,8).Trim();
start =
wea_city.IndexOf("<tdstyle="font-size:40px;font-family:TimesNewRoman;font-weight:bold;">",0,wea_city.Length);
stop = wea_city.IndexOf("℃",start) + 40;
weather2 = wea_city.Substring(start, stop-start);
weather2 = weather2.Substring(stop-start-42,40).Trim();
weather2 = weather2.Replace(" ","");
start = wea_city.IndexOf("<fontcolor=#183888><b>", 0,
wea_city.Length);
stop = wea_city.IndexOf("</b></font>",start);
wea = wea_city.Substring(start,stop-start);
wea = wea.Substring(22,wea.Length-22) + "kbrk";
wea = wea.Replace(" ", "");
wea = wea.Replace(">", "k");
wea = wea.Replace("<", "k");
wea = wea.Replace("kbrk", "k");
string [] wall = null;
char[] seperator = ...{'k'};
wall = wea.Split(seperator);
/**///////////////////////////////////////
l_city.Text = "[城市]:" + city;
l_wea.Text = "[天气]:" + weather1;
l_sky.Text = "[温度]:" + weather2;
/**////////
l_date.Text = wall[0];
l_w1.Text = wall[1];
l_w2.Text = wall[2];
l_w3.Text = wall[3];
}
public string weather_city(string city)
...{
string temp = null;
try
...{
string strURL =
"http://weather.news.sina.com.cn/cgi-bin/figureWeather/search.cgi";
HttpWebRequest request;
request = (HttpWebRequest)WebRequest.Create(strURL);
request.Method="POST"; //Post请求方式
request.ContentType="application/x-www-form-urlencoded"; //内容类型
string paraUrlCoded = System.Web.HttpUtility.UrlEncode("city");
//参数经过URL编码
paraUrlCoded = paraUrlCoded + "=" +
System.Web.HttpUtility.UrlEncode(city,
System.Text.Encoding.GetEncoding("GB2312"));
byte[] payload;
payload =
System.Text.Encoding.GetEncoding("GB2312").GetBytes(paraUrlCoded);