title: C# CR must be followed by LF
body: <p>I write a very simple HTTP server by myself, and I use the C# Windows Form to retrieve the content of my HTTP server. My C# program always said protocol violation, CR must be followed by LF. I know this issue can be solved by adding Configuration Files to C# Projects. But I want to know the exactly reason. My http server code is in below.</p>
  
  <pre><code>/*
   * This will handle connection for each client
   * */
  void *httpconnection_handler(void *socket_desc)
  {
      //Get the socket descriptor
      int sock = *(int*)socket_desc;
      int read_size;
      char *message = "HTTP/1.1 200 OK\r\nContent-Type: text/xml; \r\ncharset=utf-8\r\n\r\n";
      char *end = "\r\n";
      char send_message[3000] = {0};
  
      //Send some messages to the client
      char * buffer = 0;
      long length;
      FILE * f = fopen ("/mnt/internal_sd/device-desc.xml", "r");
      if (f)
      {
        fseek (f, 0, SEEK_END);
        length = ftell (f);
        fseek (f, 0, SEEK_SET);
        buffer = malloc (length);
        if (buffer)
        {
          fread (buffer, 1, length, f);
        }
        fclose (f);
      }
  
      strcat(send_message, message);
      strcat(send_message, buffer);
      strcat(send_message, end);
  
  
      write(sock , send_message , length + strlen(message));
      sleep(1);
      shutdown(sock, SHUT_WR);
      //Free the socket pointer
      close(sock);
  
      return 0;
  }
  </code></pre>
  
  <p>My C# code is in below.</p>
  
  <pre><code>using (WebClient webClient = new WebClient())
  {
      webClient.Encoding = Encoding.UTF8;
      contents = webClient.DownloadString(url);
  }
  </code></pre>
  
  <p>The exactly exception message is</p>
  
  <blockquote>
    <p>RequestFailed: The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF</p>
  </blockquote>