sobota, 29 września 2012

the server committed a protocol violation. section=responsestatusline

I get the following exception:
"...the server committed a protocol violation. section=responsestatusline"

The are two ways to fix it.

1. The easiest one is including a .config file in application containing the following lines:

<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing = "true"/>
</settings>
</system.net>





2. Add reference to System.configuration in your project. Then use System.Reflection and call this method:

public static bool SetAllowUnsafeHeaderParsing20()
{
Assembly aNetAssembly = Assembly.GetAssembly(typeof(System.Net.Configuration.SettingsSection));
    if (aNetAssembly != null){
        Type aSettingsType = aNetAssembly.GetType("System.Net.Configuration.SettingsSectionInternal");
        if (aSettingsType != null){
            object anInstance = aSettingsType.InvokeMember("Section",
                BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic, null, null, new object[] { });

            if (anInstance != null){
                FieldInfo aUseUnsafeHeaderParsing = aSettingsType.GetField("useUnsafeHeaderParsing", BindingFlags.NonPublic | BindingFlags.Instance);
                if (aUseUnsafeHeaderParsing != null){
                    aUseUnsafeHeaderParsing.SetValue(anInstance, true);
                    return true;
                }
            }
        }
    }
    return false;
}

Brak komentarzy:

Prześlij komentarz