2011-05-17 110 views
0

我得到Connection timed out: connect如何通過代理從HTTPS URL獲取數據?

我的代碼:

System.setProperty("http.proxyHost", "proxy.mycompany.com"); 
    System.setProperty("http.proxyPort", "8080"); 

    String url = URL_BASE + "&limit=5"; 
    URL u = new URL(url); 
    BufferedReader in = new BufferedReader(
      new InputStreamReader(
      u.openStream())); 

    String inputLine; 

    while ((inputLine = in.readLine()) != null) 
     System.out.println(inputLine); 

    in.close(); 
+1

檢查您的代理服務器是否需要驗證,然後傳遞用戶名/密碼。 – sudmong 2011-05-17 08:57:57

+0

代理服務器不需要認證。 – Alex 2011-05-17 08:59:17

回答

4

如果你獲取上HTTPS URL時,則必須設置https.proxyHosthttps.proxyPort。請參閱文檔Java Networking and Proxies,第2.2節。

System.setProperty("https.proxyHost", "proxy.mycompany.com"); 
System.setProperty("https.proxyPort", "8080"); 

假設proxy.mycompany.com端口8080也是一個HTTPS代理