Articles on: How to use Proxy Guides

How to use Proxies in Java code?

Sample code for using a proxy in Java code:

import java.net.*;
import java.util.Scanner;

 

classProxyTest {
  public static void main(String[] args) throws Exception {
    InetSocketAddressproxyAddress = new InetSocketAddress("1.1.1.1", 1234); // Set proxy IP/port.
    Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress);
    URL url = new URL("http://aceproxies.com/");
    URLConnectionurlConnection = url.openConnection(proxy);
    Scanner scanner = new Scanner(urlConnection.getInputStream());
    System.out.println(scanner.next());
    scanner.close();
  }
}

Updated on: 06/01/2018

Was this article helpful?

Share your feedback

Cancel

Thank you!