Web请求编码问题
您好,我遇到以下代码的编码问题,有什么想法吗?
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);
}
我的截图是这样的;
感谢您的帮助!
Hi i'm getting encoding problems with the code below any ideas?
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);
}
My Screenshoot is like that;
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Google 因检查
useragent
HTTP 标头而臭名昭著。因为您没有将其所有内容编码为ISO-8859-9
。简单的解决方案是手动设置HttpWebRequest
的UserAgent
属性。将其设置为您想要的任何内容,下面是一个 Firefox 字符串(以及一个额外的Using
块):Google is notorious for checking the
useragent
HTTP header. Because you're not setting it its encoding everything asISO-8859-9
. The simple solution is to manually set theUserAgent
property of theHttpWebRequest
. Set it to anything you want, below is a Firefox string (and an extraUsing
block):