Quantcast
Channel: プログラム の個人的なメモ
Viewing all articles
Browse latest Browse all 860

【Java】Javaで、プロキシサーバ経由で接続する [1]

$
0
0

■ はじめに

 * 色々な方法があるみたいだが、絞る

■ プロキシサーバ経由で接続

プロキシサーバ経由で接続するためのプロパティ

`プロパティ`備考
`#
`説明
1 http.proxyHost プロキシサーバのホスト名またはIPアドレスを指定 - 2 http.proxyPort プロキシサーバのポート番号 デフォルト値:80 3 https.proxyHost SSLプロトコルによる接続で使用するプロキシサーバのホスト名またはIPアドレスを指定 - 4 https.proxyPort SSLプロトコルによる接続でプロキシサーバのポート番号 デフォルト値:443 5 http.nonProxyHosts プロキシを省略して、直接到達するホストのリスト ホストを複数指定する場合「|」で区切って設定 6 java.net.useSystemProxies SSLプロトコルによる接続でプロキシサーバのポート番号 デフォルト値:false

実装

 * 2つ方法がある
その1:起動パラメータからの設定
java -Dhttp.proxyHost=XXX.XXX.XXX.XXX -Dhttp.proxyPort=8080 -Dhttps.proxyHost=XXX.XXX.XXX.XXX -Dhttps.proxyPort=8443 <アプリケーション>
その2:ソースコードからの設定
System.setProperty("http.proxyHost", "XXX.XXX.XXX.XXX");
System.setProperty("http.proxyPort", "8080");
System.setProperty("https.proxyHost", "XXX.XXX.XXX.XXX");
System.setProperty("https.proxyPort", "8443");

■ 認証

実装

ソースコードからの設定
Authenticator.setDefault(new Authenticator() {
  @Override
  protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication("admin", "password".toCharArray());
  }
});

■ その他

 * 試してないが、Linux だと、環境変数から設定できるかも...
http://int128.hatenablog.com/entry/20120611/1339416709


関連記事

プロキシサーバソフト ~ Squid / 初期設定編 ~

https://blogs.yahoo.co.jp/dk521123/36956970.html

プロキシサーバソフト ~ Squid / Basic認証編 ~

https://blogs.yahoo.co.jp/dk521123/36962466.html

Viewing all articles
Browse latest Browse all 860

Latest Images

Trending Articles

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>