title: HttpWebRequest.GetResponse() keeps getting timed out
body: <p>i wrote a simple C# function to retrieve trade history from MtGox with following API call:</p>
  
  <pre><code>https://data.mtgox.com/api/1/BTCUSD/trades?since=&lt;trade_id&gt;
  </code></pre>
  
  <p>documented here: <a href="https://en.bitcoin.it/wiki/MtGox/API/HTTP/v1#Multi_currency_trades" rel="noreferrer">https://en.bitcoin.it/wiki/MtGox/API/HTTP/v1#Multi_currency_trades</a></p>
  
  <p>here's the function:</p>
  
  <pre><code>string GetTradesOnline(Int64 tid)
  {
      Thread.Sleep(30000);
  
      // communicate
      string url = "https://data.mtgox.com/api/1/BTCUSD/trades?since=" + tid.ToString();
      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
      HttpWebResponse response = (HttpWebResponse)request.GetResponse();
      StreamReader reader = new StreamReader(response.GetResponseStream());
  
      string json = reader.ReadToEnd();
      reader.Close();
      reader.Dispose();
      response.Close();
  
      return json;
  }
  </code></pre>
  
  <p>i'm starting at tid=0 (trade id) to get the data (from the very beginning). for each request, i receive a response containing 1000 trade details. i always send the trade id from the previous response for the next request. it works fine for exactly 4 requests &amp; responses. but after that, the following line throws a "System.Net.WebException", saying that "The operation has timed out":</p>
  
  <pre><code>HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  </code></pre>
  
  <p>here are the facts:</p>
  
  <ul>
  <li>catching the exception and retying keeps causing the same exception</li>
  <li>the default HttpWebRequest .Timeout and .ReadWriteTimeout are already high enough (over a minute)</li>
  <li>changing HttpWebRequest.KeepAlive to false didn't solve anything either</li>
  <li>it seems to always work in the browser even while the function is failing</li>
  <li>it has no problems retrieveing the response from <a href="https://www.google.com" rel="noreferrer">https://www.google.com</a></li>
  <li>the amount of successful responses before the exceptions varies from day to day (but browser always works)</li>
  <li>starting at the trade id that failed last time causes the exception immediately</li>
  <li>calling this function from the main thread instead still caused the exception</li>
  <li>running it on a different machine didn't work</li>
  <li>running it from a different IP didn't work</li>
  <li>increasing Thread.Sleep inbetween requests does not help</li>
  </ul>
  
  <p>any ideas of what could be wrong?</p>