title: WebException (Status: Protocol Error)
body: <p>I am calling a url in C# using <code>WebClient</code> class. Following is the code: -</p>
  
  <pre><code>    public string SendWebRequest(string requestUrl)
      {
          using (var client = new WebClient())
          {
              string responseText = client.DownloadString(requestUrl);
              return responseText;
          } 
      }
  </code></pre>
  
  <p>This code fails with following Exception details: -</p>
  
  <pre><code>System.Net.WebException: The remote server returned an error: (1201).
     at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest&amp; request)
     at System.Net.WebClient.DownloadString(Uri address)
     at System.Net.WebClient.DownloadString(String address)
  
  Exception Status: ProtocolError
  </code></pre>
  
  <p>URL hit the server properly. Actions expected (update database) on server happen properly. Server sends response properly. <code>WebClient</code> is not processing the response.</p>
  
  <p>I also tried using <code>HttpWebRequest</code> class without success.</p>
  
  <p>Initially, similar issue was there while request. It was resolved when I modified my <code>app.config</code> with following: -</p>
  
  <pre><code>    &lt;settings&gt;
          &lt;httpWebRequest useUnsafeHeaderParsing = "true"/&gt;
      &lt;/settings&gt;
  </code></pre>
  
  <p>I cannot post URL on this forum and anyway it is not accessible outside network.</p>
  
  <p><strong>If I copy same URL in browser address bar, it just works fine and returns expected response.</strong></p>
  
  <p>What could be the problem with windows application then?</p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>I implemented suggestions from answer. I also implemented suggestion in accepted answer for <a href="https://stackoverflow.com/questions/22623664/bad-request-400-protocol-error-on-a-valid-url-webclient">this</a> question. Now, my function looks as follows: -</p>
  
  <pre><code>    public string SendWebRequest(string requestUrl)
      {
          using (var client = new WebClient())
          {
              client.Headers.Add("Accept", "text/plain");
              client.Headers.Add("Accept-Language", "en-US");
              client.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
              client.Headers["Content-Type"] = "text/plain;charset=UTF-8";
              string responseText = client.DownloadString(requestUrl);
              return responseText;
          } 
      }
  </code></pre>
  
  <p>It still does not solve the problem. Response is now blank string ("") instead of "Success". This is not fault from server which is confirmed.</p>
  
  <p>If I remove configuration in <code>app.config</code>, it throws other exception.</p>
  
  <pre><code>System.Net.WebException: The server committed a protocol violation. Section=ResponseStatusLine
     at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest&amp; request)
     at System.Net.WebClient.DownloadString(Uri address)
     at System.Net.WebClient.DownloadString(String address)
  </code></pre>