使用WebRequest时,URL中含有中文的问题
Encoding ed=Encoding.GetEncoding("gb2312");
WebRequest req = WebRequest.Create("http://php.weather.sina.com.cn/search.php?city=" + HttpUtility.UrlEncode("北京", ed));
WebResponse response = req.GetResponse();
string content = string.Empty;
using (Stream st = response.GetResponseStream())
{
StreamReader sr = new StreamReader(st, Encoding.Default);
content = sr.ReadToEnd();
}
搞定!