C# 用HttpWebResponse解析特殊字符
我正在解析一个HTML站点,以使用C#客户端中的数据。 不幸的是,我的HTTPresponse搞乱了所有特殊字符(如法语名称),并用问号“?”替换它们。 我能做些什么来解决我的问题 这是我的密码:C# 用HttpWebResponse解析特殊字符,c#,html,parsing,special-characters,C#,Html,Parsing,Special Characters,我正在解析一个HTML站点,以使用C#客户端中的数据。 不幸的是,我的HTTPresponse搞乱了所有特殊字符(如法语名称),并用问号“?”替换它们。 我能做些什么来解决我的问题 这是我的密码: private void LoadData() { String strBaseURL = @"http://here_goes_the_url.com/"; StringBuilder sb = new StringBuilder(); byte[] buf = new by
private void LoadData()
{
String strBaseURL = @"http://here_goes_the_url.com/";
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(strBaseURL);
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
result = sb.ToString();
}
我试图更改编码,但没有任何结果:(
谢谢!您必须使用ASCII以外的其他语言 试试这个,例如:
tempString = Encoding.UTF8.GetString(buf, 0, count);
原因是编码只覆盖127位字符集,而覆盖字符集中的所有字符。您必须使用ASCII以外的其他字符 试试这个,例如:
tempString = Encoding.UTF8.GetString(buf, 0, count);
原因是编码只覆盖127位字符集,而覆盖了字符集中的所有字符。成功了!非常感谢,我先尝试了UniCode和UTF32,但没有成功,UTF8和我可以看到所有字符:)成功了!非常感谢,我首先尝试使用UniCode和UTF32,但没有成功,UTF8和我可以看到所有字符:)