title: Error on some urls only : java.net.ConnectException: Connection timed out: connect
body: <p>I would like to download ics files with a Java application, so that I simply tried the code at this page : <a href="http://hc.apache.org/httpclient-legacy/tutorial.html" rel="nofollow">http://hc.apache.org/httpclient-legacy/tutorial.html</a> (at the bottom). </p>
  
  <p>All is right with many urls, but this one gaves me the error in title : <a href="http://www.sportycal.com/cal/getIcs/id/264/remider/1/ct/any/sportycal.ics" rel="nofollow">http://www.sportycal.com/cal/getIcs/id/264/remider/1/ct/any/sportycal.ics</a></p>
  
  <p>I think it's not a configuration problem from my IDE because it works for the first url... </p>
  
  <p>Morevoer, I can download the file from the second URL with my browser, and I get this headers : </p>
  
  <pre><code>Request URL:url_du_site
  Request Method:GET
  Status Code:200 OK
  </code></pre>
  
  <p><strong>Request Headers</strong></p>
  
  <pre><code>Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Accept-Encoding:gzip,deflate,sdch
  Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
  Host:www.sportycal.com
  Proxy-Connection:keep-alive
  User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
  </code></pre>
  
  <p><strong>Response Headers</strong></p>
  
  <pre><code>Access-Control-Allow-Origin:*
  Connection:close
  Content-Disposition:attachment; filename=cal.ics
  Content-Type:text/calendar; charset=utf-8
  Date:Fri, 25 Oct 2013 08:11:16 GMT
  Server:Apache/2.2.14 (Ubuntu)
  Set-Cookie:symfony=8p9gbbp301jhteu52e2qu1nie0; path=/
  X-Cache:MISS from office-proxy.priv.atos.fr
  X-Cache-Lookup:MISS from office-proxy.***.fr:3128
  X-Powered-By:PHP/5.3.2-1ubuntu4.18
  </code></pre>
  
  <p>I thought about this one : Connection:close.
  I sought the RFC, but I don't really understand what it means.. Do you think the non-persistent connection could be the reason it does not work?
  What can I do to get this file?</p>
  
  <p>Thank you by advance for your help!</p>
  
  <p>(Sorry if my english is not really good, I hope you understand anyway...)</p>
  
  <p>Edit : </p>
  
  <p>The code I tried is really the same as the tutorial : </p>
  
  <pre><code>public static void main(String[] args) {
      String url = "http://www.sportycal.com/cal/getIcs/id/264/remider/1/ct/any/sportycal.ics";
      readUrl(url);
  }
  
  
  private static void readUrl(String url) {
      // Create an instance of HttpClient.
      HttpClient client = new HttpClient();
  
      // Create a method instance.
      GetMethod method = new GetMethod(url);
  
      // Provide custom retry handler is necessary
      method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
              new DefaultHttpMethodRetryHandler(3, false));
  
      try {
        // Execute the method.
        int statusCode = client.executeMethod(method);
  
        if (statusCode != HttpStatus.SC_OK) {
          System.err.println("Method failed: " + method.getStatusLine());
        }
  
        // Read the response body.
        byte[] responseBody = method.getResponseBody();
  
        // Deal with the response.
        // Use caution: ensure correct character encoding and is not binary data
        System.out.println(new String(responseBody));
  
      } catch (HttpException e) {
        System.err.println("Fatal protocol violation: " + e.getMessage());
        e.printStackTrace();
      } catch (IOException e) {
        System.err.println("Fatal transport error: " + e.getMessage());
        e.printStackTrace();
      } finally {
        // Release the connection.
        method.releaseConnection();
      }  
  
  
  }
  </code></pre>
  
  <p>And the stack trace I get is the following : </p>
  
  <pre><code>Fatal transport error: Connection timed out: connect
  java.net.ConnectException: Connection timed out: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
      at java.net.Socket.connect(Socket.java:529)
      at java.net.Socket.connect(Socket.java:478)
      at java.net.Socket.&lt;init&gt;(Socket.java:375)
      at java.net.Socket.&lt;init&gt;(Socket.java:249)
      at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:79)
      at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:121)
      at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
      at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
      at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
      at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
      at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
      at tests.TestUrl.readUrl(TestUrl.java:46)
      at tests.TestUrl.main(TestUrl.java:28)
  </code></pre>
  
  <p>Edit 2 : 
  It looks like it is because of my environment : I tried on distant server and it seems to work !! But why it is okay for some urls, and wrong for others... 
  No other ideas please ?</p>