Der server verpflichtet, eine Protokollverletzung. Abschnitt=ResponseStatusLine in c#

Habe ich verbrachte einen ganzen Tag versuchen, diese zu lösen. Ich habe eine benutzerdefinierte webserver und Anforderungen, um es von Chrome oder POSTman ReST client funktionieren. Sobald ein s ich verwenden webclient oder httpwebrequest-Klasse in c#, ich bekomme die Meldung : Der server verpflichtet, eine Protokollverletzung. Abschnitt=ResponseStatusLine wenn Sie versuchen, übertragen Sie eine zip-Datei an den client.

Habe ich versucht:

public static bool SetAllowUnsafeHeaderParsing20()
{
    //Get the assembly that contains the internal class
    Assembly aNetAssembly = Assembly.GetAssembly(typeof(System.Net.Configuration.SettingsSection));
    if (aNetAssembly != null)
    {
        //Use the assembly in order to get the internal type for the internal class
        Type aSettingsType = aNetAssembly.GetType("System.Net.Configuration.SettingsSectionInternal");
        if (aSettingsType != null)
        {
            //Use the internal static property to get an instance of the internal settings class.
            //If the static instance isn't created allready the property will create it for us.
            object anInstance = aSettingsType.InvokeMember("Section", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic, null, null, new object[] { });
            if (anInstance != null)
            {
                //Locate the private bool field that tells the framework is unsafe header parsing should be allowed or not
                FieldInfo aUseUnsafeHeaderParsing = aSettingsType.GetField("useUnsafeHeaderParsing", BindingFlags.NonPublic | BindingFlags.Instance);
                if (aUseUnsafeHeaderParsing != null)
                {
                    aUseUnsafeHeaderParsing.SetValue(anInstance, true);
                    return true;
                }
            }
        }
    }
    return false;
}

und

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

in der app.config.

Habe ich auch schon versucht keep-alive=false und versaut mit dem Header zu/

Dies ist die webrequest, die nicht auf client2Downloadfile nennen:

private void sendManifest()
{

    Uri remoteuri = new Uri(Properties.Settings.Default.masterurl);

    SetAllowUnsafeHeaderParsing20();
    using (WebClient client = new WebClient())
    {
        NameValueCollection reqparm = new NameValueCollection();
        reqparm.Add("application", "TestApp");
        reqparm.Add("manifest", manifest);
        try
        {
            byte[] responsebytes = client.UploadValues(Properties.Settings.Default.masterurl, "POST", reqparm);
            string responsebody = Encoding.UTF8.GetString(responsebytes);
            if (responsebody != "")
            {
                using (WebClient client2 = new WebClient())
                {
                    client2.DownloadFile(Properties.Settings.Default.masterurl + "//" + responsebody + "transfer.zip", "c:\\temp.zip");
                }
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }
    }
}

Den webserver-Antwort gesehen werden kann auf :

http://gplus2.net:9532/97e456f0-9b57-4315-b03d-40a67f76d440/transfer.zip

Jede Hilfe wird sehr geschätzt, da habe ich buchstäblich die Ideen ausgehen. Es ist offensichtlich eine fehlerhafte server-header, aber ich habe es auf ein minimum.

InformationsquelleAutor spanout | 2014-05-19

Schreibe einen Kommentar