日期:2014-05-18  浏览次数:20928 次

c#获取天气,编译通过了,怎么无法返回!求帮忙
static string GetWeatherInfo(string s1, string s2) 
  { 
  string ResponseText; 
  string text; 
  int startIndex; 
  int endIndex;
  Uri url = new Uri(@"http://www.7stk.com/1/6/weather2.htm"); 
  HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); 
  HttpWebResponse res = (HttpWebResponse)req.GetResponse(); 
  req.Method = "Post"; 
  StreamReader ReaderText = new StreamReader(res.GetResponseStream(), Encoding.UTF8); 
  ResponseText = ReaderText.ReadToEnd(); 
  res.Close(); 
  startIndex = ResponseText.IndexOf(s1) + s1.Length; 
  endIndex = ResponseText.IndexOf(s2); 
  text = ResponseText.Substring(startIndex, endIndex-startIndex); 
  return text; 
  } 
 
  private void Form1_Load(object sender, EventArgs e) 
  { 
  label4.Text = GetWeatherInfo(@"g>", @"</"); 
  label5.Text = GetWeatherInfo(@"天气:", @",紫"); 
  }


是网站不行吗?http://www.7stk.com/1/6/weather2.htm

------解决方案--------------------
这个WS一直很稳定
http://www.webxml.com.cn/WebServices/WeatherWebService.asmx