none
C# winform获取本地天气显示到label里 RRS feed

  • 问题

  • 在网上找了一下代码发现不能运行请问错在哪里呢?

    	static string GetWeather(string s1,string s2)
    
    	{
    
    			string ResponseText;
    
    			string temp;
    
    			int startIndex;
    
    			int endIndex;
    
    			Uri url= new Uri(@"http://firetear.com/weather/lvweather.aspx");
    
    			HttpWebRequest hwReq = (HttpWebRequest)WebRequest.Create(url); 
    
    			HttpWebResponse hwRes = (HttpWebResponse)hwReq.GetResponse(); 
    
    			hwReq.Method = "Post"; 
    
    			StreamReader ReaderText = new StreamReader(hwRes.GetResponseStream(),Encoding.UTF8); 
    
    			//ResponseText = ReaderText.ReadLine() ; 
    
    			ResponseText = ReaderText.ReadToEnd(); 
    
    			hwRes.Close(); 
    
    			startIndex = ResponseText.IndexOf(s1) + s1.Length;
    
    			endIndex = ResponseText.IndexOf(s2);
    
    			temp = ResponseText.Substring(startIndex,endIndex - startIndex);
    
    			//temp = ResponseText.Substring(startIndex + 1,endIndex -1 - startIndex);
    
    			
    
    			//return ResponseText;
    
    			return temp;
    
    	}
    
    
    	string GetIp()
    
    	{
    
                                    Uri uri = new Uri("http://fw.qq.com/ipaddress");//查本机网络IP的网页
    
    		HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
    
    		req.Method = "POST";
    
    		req.ContentType = "application/x-www-form-urlencoded";
    
    		req.ContentLength = 0;
    
    		req.CookieContainer = new CookieContainer();
    
    		req.GetRequestStream().Write(new byte [0], 0, 0);
    
    		HttpWebResponse res = (HttpWebResponse)(req.GetResponse());
    
    		StreamReader rs = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding("GB18030"));
    
    		string s = rs.ReadToEnd();
    
    		rs.Close();
    
    		req.Abort();
    
    		res.Close();
    
    		Match m = Regex.Match(s, @"IP:\[(?<IP>[0-9\.]*)\]");
    
    		if (m.Success) return m.Groups["IP"].Value;
    
    		string strnetIP= string.Empty;
    
    		return strnetIP;
    
                      }
    
    

    我只是要把这两个函数返回的字符串,然后再把天气信息字符串显示在label里,但是运行的时候不行,是代码里面那个网址不行吗,我这里有一个网址:http://fw.qq.com/ipaddress

    不知道现在怎麽做,求大侠指点

     


    2011年9月22日 13:16

答案

全部回复