All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.dongliu.requests.Proxies Maven / Gradle / Ivy

There is a newer version: 5.0.8
Show newest version
package net.dongliu.requests;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.Objects;

/**
 * Utils class for create Proxy
 *
 * @author Liu Dong
 */
public class Proxies {
    /**
     * Create http proxy
     */
    public static Proxy httpProxy(String host, int port) {
        return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(Objects.requireNonNull(host), port));
    }

    /**
     * Create http proxy, with authentication
     */
//    public static Proxy httpProxy(String host, int port, String user, String password) {
//        Objects.requireNonNull(user);
//        Objects.requireNonNull(password);
//        return new AuthenticationHttpProxy(new InetSocketAddress(Objects.requireNonNull(host), port),
//                new BasicAuth(user, password));
//    }

    /**
     * Create socks5 proxy
     */
    public static Proxy socksProxy(String host, int port) {
        return new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(Objects.requireNonNull(host), port));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy