请问C#中的WebResponse.CharacterSet是通过真么得到的?是WebResponse.ContentType吗?

[已解决] 请问C#中的WebResponse.CharacterSet是通过真么得到的?是WebResponse.ContentType吗?

10
[Web开发 > ASP.NET]
请问C#中的WebResponse.CharacterSet是通过真么得到的?是WebResponse.ContentType吗?
提问时间:2010/7/21 13:19:33 | 提问者:Souidea | 悬赏:10 | 浏览:753
最佳答案
正确,这个是.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;
   }
}
回答时间:2010/7/21 13:24:23 | 回答者:56max
其他参考答案(0)
提交失败!请检查错误!错误信息:

注:以上所有信息由网友提供,仅供交流、参考,均不代表盛派网络言论,如果有任何问题或不妥,请立即联系我们

以下信息或许对您有用: