Web请求编码问题

时间:2011-05-17 13:09:21

标签: asp.net character-encoding httpwebrequest

您好我的代码编码问题出现在任何想法之下?

string url = "http://www.google.com/ig/api?weather=istanbul,TR&hl=tr";
        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        {
            StreamReader reader = new StreamReader(response.GetResponseStream());
            string retVal = reader.ReadToEnd();
            Response.Write(retVal);
        }

我的屏幕截图就是这样;

enter image description here

感谢您的帮助!

1 个答案:

答案 0 :(得分:4)

谷歌以检查useragent HTTP标头而臭名昭着。因为您没有将其编码为ISO-8859-9。简单的解决方案是手动设置UserAgent的{​​{1}}属性。将它设置为您想要的任何内容,下面是一个Firefox字符串(以及一个额外的HttpWebRequest块):

Using