服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF 解决方案

2013-12-16_062702

Better Life

显示行号 复制代码 处理『服务器提交了协议冲突』
  1. #region 处理『服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF』
    
  2.         //需引用 using System.Reflection;
    
  3.         public static bool SetAllowUnsafeHeaderParsing()
    
  4.         {
    
  5.             //Get the assembly that contains the internal class
    
  6.             Assembly aNetAssembly = Assembly.GetAssembly(
    
  7.             typeof(System.Net.Configuration.SettingsSection));
    
  8.             if (aNetAssembly != null)
    
  9.             {
    
  10.                 //Use the assembly in order to get the internal type for 
    
  11.                 // the internal class
    
  12.                 Type aSettingsType = aNetAssembly.GetType(
    
  13.                 "System.Net.Configuration.SettingsSectionInternal");
    
  14.                 if (aSettingsType != null)
    
  15.                 {
    
  16.                     //Use the internal static property to get an instance 
    
  17.                     // of the internal settings class. If the static instance 
    
  18.                     // isn't created allready the property will create it for us.
    
  19.                     object anInstance = aSettingsType.InvokeMember("Section",
    
  20.                     BindingFlags.Static | BindingFlags.GetProperty
    
  21.                     | BindingFlags.NonPublic, null, null, new object[] { });
    
  22.                     if (anInstance != null)
    
  23.                     {
    
  24.                         //Locate the private bool field that tells the 
    
  25.                         // framework is unsafe header parsing should be 
    
  26.                         // allowed or not
    
  27.                         FieldInfo aUseUnsafeHeaderParsing = aSettingsType.GetField(
    
  28.                         "useUnsafeHeaderParsing",
    
  29.                         BindingFlags.NonPublic | BindingFlags.Instance);
    
  30.                         if (aUseUnsafeHeaderParsing != null)
    
  31.                         {
    
  32.                             aUseUnsafeHeaderParsing.SetValue(anInstance, true);
    
  33.                             return true;
    
  34.                         }
    
  35.                     }
    
  36.                 }
    
  37.             }
    
  38.             return false;
    
  39.         }
    
  40. 
    
  41.         #endregion
    
  42. 
    

转载自:http://blog.sina.com.cn/s/blog_6051c4e801010dnt.html

点赞