AnsweredAssumed Answered

ITHit.WebDAV.Client: The server committed a protocol violation: Section=ResponseStatusLine

Question asked by mathias.lin on Aug 11, 2016
I have a C# application where I upload a certain folder and file structure to a remote WebDav server (Alfresco repository) via the ITHit WebDav Client library. It's a couple of hundred of files (pdf, txt, doc, etc.) and subfolders.

Most of them can be uploaded just fine, but for some documents (and always the same whenever I run my code), I get an error message:


An unhandled exception of type 'ITHit.WebDAV.Client.Exceptions.WebDavException' occurred in
ITHit.WebDAV.Client.dll

Additional information: The server committed a protocol violation..
Section=ResponseStatusLine


The error occurs either at the point when I try to upload a file (in particular at the folder.CreateResource(…) line):


IFolder folder = …
ITHit.WebDAV.Client.IResource wdFileDestination =
folder.CreateResource(System.IO.Path.GetFileName(file));
wdFileDestination.Upload(file);


or sometimes when I just want to check whether a resource exists on the remote server:
</code>


if (folder.ItemExists(dirName))


It seems that something is wrong with the response of the WebDav/Alfresco server, however assuming that I am not able to change the server response, I must handle it on client-side.

I googled for it and already found something about a flag named useUnsafeHeaderParsing, but it did no help so far.

I already added a section


<httpWebRequest useUnsafeHeaderParsing="true"/>


in my App.config


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.net>
    <settings>
      <httpWebRequest useUnsafeHeaderParsing="true"/>
    </settings>
  </system.net>
</configuration>


as recommended here: C#: Handling WebClient "protocol violation" (12 upvotes) or here The server committed a protocol violation. Section=ResponseStatusLine ERROR (70 upvotes).

I also added a method to my code and enabled it via code as well (after just adding it to App.config did not help):


ToggleAllowUnsafeHeaderParsing(true);


with the method as defined here: https://o2platform.wordpress.com/2010/10/20/dealing-with-the-server-committed-a-protocol-violation-sectionresponsestatusline/

Seems that the ITHit WebDav client ignores this flag.

Maybe there is something that can be done on the ITHit Webdav client side, but I have not yet found anything useful in the documentation (https://doc3.webdavsystem.com/ITHit.WebDAV.Client.htm) yet. Has anyone had this problem before as well, especially in combination with the ITHit WebDav library that I am using.

Or does maybe anyone from the Alfresco community know about this protocol violation problem on Alfresco side?

By the way: I can upload the very same files with any other WebDav client (Windows Explorer, NetDrive, etc.) to that particular WebDav/Alfresco server without problems, just happens in my C# code.

(Originally posted on StackOverflow: http://stackoverflow.com/questions/38896377/ithit-webdav-client-the-server-committed-a-protocol-violation-section-response)

Outcomes