asp. net method for obtaining weather forecast according to city
- 2021-07-10 19:22:11
- OfStack
In this paper, the method of obtaining weather forecast according to cities by asp. net is described with examples. Share it for your reference, as follows:
public void GetWetheaerByCity(string cityName) {
string city = cityName;
string mycity = HttpUtility.UrlEncode(city, System.Text.Encoding.GetEncoding("GB2312"));
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://www.sina.com/index.php?city=" + cityName);
//HttpWebRequest Object Get GetResponse Convert to HttpWebResponse
System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse;
// Pass HttpWebResponse response.GetResponseStream() Get the output stream
Stream str = response.GetResponseStream();
StreamReader reader = new StreamReader(str, System.Text.Encoding.GetEncoding("GB2312"));
string weathhtml = reader.ReadToEnd();
str.Close();
reader.Close();
}
I hope this article is helpful to everyone's asp. net programming.