title: The underlying connection was closed exception while WebClient DownloadString
body: <p>Just a piece of code</p>
  
  <pre><code>WebClient wc = new WebClient();
  String str = wc.DownloadString(new Uri("http://content.warframe.com/dynamic/rss.php"));
  </code></pre>
  
  <p>And I got exception:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.Net.WebException' occurred in
    System.dll</p>
    
    <p>Additional information: The underlying connection was closed: The
    connection was closed unexpectedly.</p>
  </blockquote>
  
  <p>I've head that this is a bug in .NET (I am using 3.5), but I tried other methods to obtain the content of this link (its rss, xml). No lucky shot yet</p>
  
  <pre><code>var webrequest = (WebRequest)HttpWebRequest.Create(@"http://content.warframe.com/dynamic/rss.php");
  var resp = webrequest.GetResponse();
  //HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse(); // Wont work also
  </code></pre>
  
  <p>This code above won't work either, both casts the same exception</p>
  
  <p><strong>Fiddler logs:</strong><br></p>
  
  <p>SESSION STATE: Aborted.<br>
  Response Entity Size: 512 bytes.<br></p>
  
  <p>== FLAGS ==================<br>
  BitFlags: [ResponseGeneratedByFiddler] 0x100<br>
  X-ABORTED-WHEN: Done<br>
  X-CLIENTIP: 127.0.0.1<br>
  X-CLIENTPORT: 2747<br>
  X-EGRESSPORT: 2748<br>
  X-FAILSESSION-WHEN: ReadingResponse<br>
  X-HOSTIP: 205.185.216.10<br>
  X-PROCESSINFO: willitwork.vshost:3300<br><br></p>
  
  <p>== TIMING INFO ============<br>
  ClientConnected:    10:29:11.706<br>
  ClientBeginRequest: 10:29:11.713<br>
  GotRequestHeaders:  10:29:11.713<br>
  ClientDoneRequest:  10:29:11.713<br>
  Determine Gateway:  0ms<br>
  DNS Lookup:         164ms<br>
  TCP/IP Connect: 74ms<br>
  HTTPS Handshake:    0ms<br>
  ServerConnected:    10:29:11.953<br>
  FiddlerBeginRequest:    10:29:11.953<br>
  ServerGotRequest:   10:29:11.953<br>
  ServerBeginResponse:    10:29:12.372<br>
  GotResponseHeaders: 00:00:00.000<br>
  ServerDoneResponse: 10:29:12.372<br>
  ClientBeginResponse:    10:29:12.385<br>
  ClientDoneResponse: 10:29:12.385<br></p>
  
  <p>Overall Elapsed:    0:00:00.672<br><br></p>
  
  <p>The response was buffered before delivery to the client.<br><br></p>
  
  <p>== WININET CACHE INFO ============<br>
  This URL is not present in the WinINET cache. [Code: 2]<br>
  * Note: Data above shows WinINET's current cache state, not the state at the time of the request.<br>
  * Note: Data above shows WinINET's Medium Integrity (non-Protected Mode) cache only.<br></p>
  
  <p>Also - 504, this does not makes sense since I can get data from link via chrome / firefox / ie...</p>
  
  <p>I just did it to work in other language, but I am forced to do it with C# (I' ve made 2 much code to rewrite it)</p>
  
  <p>I've added some settings like fiddler said</p>
  
  <pre><code>myHttpWebRequest1.ProtocolVersion = HttpVersion.Version11;
  myHttpWebRequest1.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36";
  myHttpWebRequest1.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
  </code></pre>
  
  <p>At least now I get 504 error instead of "unknown", but I can still view the content via webbrowser, so the 504 error is <strong>fake</strong></p>
  
  <p>Edit: There is no response error when I added</p>
  
  <pre><code>myHttpWebRequest1.Headers["Accept-Encoding"] = "gzip";
  </code></pre>
  
  <p>but now the output is messed and unreadable</p>