If you need to set proxy address on Java HttpURLConnection. Do something like below. public static String getString(String urlStr) throws Exception { HttpURLConnection connection = null; InputStream is = null; try { URI uri = new URI(urlStr); // settin proxy String proxyHost = ""; // your proxy serever address int proxyPort = 8080; // your proxy port Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); // open connection with passing Proxy Object connection = (HttpURLConnection)uri.toURL().openConnection(proxy); connection.connect(); is = connection.getInputStream(); String content = toString(is); return content; } finally{ closeQuietly(is); if(connection != null) { connection.disconnect(); } } } private static String toString(InputStream is) throws IOException { byt...
IT関連の技術やプログラミングを中心に記事を書いています。ハードウェアも好きなので、日々のちょっとしたお役立ち情報も投稿しています。