请问C#中的WebResponse.CharacterSet是通过真么得到的?是WebResponse.ContentType吗?
[已解决] 请问C#中的WebResponse.CharacterSet是通过真么得到的?是WebResponse.ContentType吗?
当前页面:http://www.senparc.com/SZD-160
{ 收藏当前页面 }
最佳答案
正确,这个是.NET Framework的实现:
public string CharacterSet
{
get
{
this.CheckDisposed();
string contentType = this.m_HttpResponseHeaders.ContentType;
if ((this.m_CharacterSet == null) && !ValidationHelper.IsBlankString(contentType))
{
this.m_CharacterSet = string.Empty;
string str2 = contentType.ToLower(CultureInfo.InvariantCulture);
if (str2.Trim().StartsWith("text/"))
{
this.m_CharacterSet = "ISO-8859-1";
}
int index = str2.IndexOf(";");
if (index > 0)
{
while ((index = str2.IndexOf("charset", index)) >= 0)
{
index += 7;
if ((str2[index - 8] == ';') || (str2[index - 8] == ' '))
{
while ((index < str2.Length) && (str2[index] == ' '))
{
index++;
}
if ((index < (str2.Length - 1)) && (str2[index] == '='))
{
index++;
int num2 = str2.IndexOf(';', index);
if (num2 > index)
{
this.m_CharacterSet = contentType.Substring(index, num2 - index).Trim();
}
else
{
this.m_CharacterSet = contentType.Substring(index).Trim();
}
break;
}
}
}
}
}
return this.m_CharacterSet;
}
}
public string CharacterSet
{
get
{
this.CheckDisposed();
string contentType = this.m_HttpResponseHeaders.ContentType;
if ((this.m_CharacterSet == null) && !ValidationHelper.IsBlankString(contentType))
{
this.m_CharacterSet = string.Empty;
string str2 = contentType.ToLower(CultureInfo.InvariantCulture);
if (str2.Trim().StartsWith("text/"))
{
this.m_CharacterSet = "ISO-8859-1";
}
int index = str2.IndexOf(";");
if (index > 0)
{
while ((index = str2.IndexOf("charset", index)) >= 0)
{
index += 7;
if ((str2[index - 8] == ';') || (str2[index - 8] == ' '))
{
while ((index < str2.Length) && (str2[index] == ' '))
{
index++;
}
if ((index < (str2.Length - 1)) && (str2[index] == '='))
{
index++;
int num2 = str2.IndexOf(';', index);
if (num2 > index)
{
this.m_CharacterSet = contentType.Substring(index, num2 - index).Trim();
}
else
{
this.m_CharacterSet = contentType.Substring(index).Trim();
}
break;
}
}
}
}
}
return this.m_CharacterSet;
}
}
回答时间:2010/7/21 13:24:23
| 回答者:56max
其他参考答案(0)
提交失败!请检查错误!错误信息:
以下信息或许对您有用:
- [已解决] 20 ASP.NET 4.0中关于图标、SEO、页面输出缓存(Charts,SEO,O... 2010/10/15 12:41:36
- [已解决] 10 Unable to read data from the transport c... 2010/10/9 15:45:37
- [已解决] 20 如何让线程停止,等待10秒钟? 2010/9/9 22:51:30
- [已解决] 20 最新的Razor模板语法介绍在哪里可以找到? 2010/8/5 14:21:42