顯然,Google的編碼是UTF-8,因爲它是在html元標記中聲明的。 但是當我用ASP WebRequest.GetResponse()打開scharfes + s的搜索頁面時,它充滿了無法識別的字符。有人知道那裏發生了什麼嗎?谷歌的字符編碼是什麼?
爲了您的方便,代碼粘貼下面
ASP頁
<form id="form1" runat="server">
<div>
<div runat="server" id="output"/>
</div>
</form>
代碼隱藏
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Text;
public partial class SearchEngineCaller : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpWebRequest queryPage = (HttpWebRequest)WebRequest.Create("https://www.google.com/search?q=scharfes+s");
queryPage.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)queryPage.GetResponse();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
output.InnerHtml = readStream.ReadToEnd();
}
}
我應該使用什麼編碼?
當您直接從瀏覽器打開此頁面時是否看到相同的問題? https://www.google.com/search?q=scharfes+s – kol
不。這一切都正確使用我的瀏覽器 –
試試這個:http://stackoverflow.com/a/5861309/600135 – kol