JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
作者 請問如何用java設定proxy?
noneman





發文: 159
積分: 0
於 2013-10-25 15:10 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
小弟的公司正在和刷卡廠商串接資料,但由於測試主機有設防火牆,雖網管有幫小弟開通,但依然連不出去,網管試著由tomcat設定proxy但還是不行,後來主管說要小弟用java去設定proxy,但小弟沒寫過這方面的程式,故想請教各位如何用java設定proxy呢?

小弟有試著這樣設定,想故意讓牠連不出去,但失敗了,連的很順,代表這設定好像沒作用說=.=

附原始碼,就麻煩有經驗的前輩幫我看看吧= =
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
 
public class Sms {
  
  public static void main(String[] args) throws Exception {
    String sURLString = "http://www.google.com.tw";
    
    HttpURLConnection huc = null;
    BufferedReader buReader = null;
    
    try {
      
      //System.out.println(System.getProperty("http.proxyHost"));
      //System.setProperty("http.proxySet", "true");
      //System.setProperty("http.proxyHost", "0.0.2.3");
      //System.setProperty("http.proxyPort", "3344"); 
      
      System.getProperties().setProperty("http.proxySet","true");
      System.getProperties().setProperty("http.proxyHost","2.69.7774.1");
      System.getProperties().setProperty("http.proxyPort", "0000");
      
      huc = (HttpURLConnection)new URL(sURLString).openConnection();
 
      huc.setInstanceFollowRedirects(true);
      huc.setDoInput(true);
      huc.setDoOutput(true);
      huc.setUseCaches(false);
      huc.setRequestMethod("GET");
      
      buReader = new BufferedReader(new InputStreamReader(huc.getInputStream(), "UTF-8"));
      String sLine;
      
      while ((sLine = buReader.readLine()) != null)
        System.out.println(sLine);
        
      
    } catch (Exception e) {
      System.out.println("Sms:" + e.toString());
    } finally {
      try {
        if (buReader != null) buReader.close();
      } catch (Exception e) {
      } finally {
        buReader = null;
      }
      
      
      huc = null;
    }
  }
}
 


noneman edited on 2013-10-28 09:11
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
1063 請問如何用java設定proxy? noneman 1717 2013-10-25 15:10
» JWorld@TW »  Java 新手區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8