통합

Shifter와 함께 사용 Java

Shifter의 레지덴셜 및 ISP 프록시를 몇 분 안에 Java 애플리케이션에 연결하세요. 내장 HttpClient(Java 11+), OkHttp, Apache HttpClient, Selenium, Jsoup과 함께 작동하며 SDK가 필요하지 않습니다.

빠른 시작

설치

// Maven
// <dependency><groupId>com.squareup.okhttp3</groupId><artifactId>okhttp</artifactId><version>4.12.0</version></dependency>

기본 사용법

import java.net.*;
import java.net.http.*;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Quickstart {
  public static void main(String[] args) throws Exception {
    Authenticator auth = new Authenticator() {
      @Override
      protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(
          "customer-USERNAME-country-us-sid-123ABC",
          "PASSWORD".toCharArray());
      }
    };

    HttpClient client = HttpClient.newBuilder()
      .proxy(ProxySelector.of(new InetSocketAddress("p.shifter.io", 443)))
      .authenticator(auth)
      .build();

    HttpRequest request = HttpRequest.newBuilder()
      .uri(URI.create("https://ipinfo.io/json"))
      .GET()
      .build();

    HttpResponse<String> response =
      client.send(request, HttpResponse.BodyHandlers.ofString());

    System.out.println(response.body());
  }
}

기능

HttpClient (Java 11+), OkHttp, Apache HttpClient, RestTemplate, WebClient에 대한 즉시 지원
기본값은 요청별 로테이션이며, 스티키 세션에는 `sid`를, N초 동안의 시간제 고정에는 `ttl-N`을 사용합니다
Selenium WebDriver 및 Java용 Playwright를 통한 헤드리스 브라우저 지원
동일한 게이트웨이 엔드포인트에서 지원되는 HTTP, HTTPS, SOCKS5 프로토콜
사용자 이름 매개변수를 통한 195개국 이상 Geo 타겟팅 - 추가 종속성 불필요
Java 8, 11, 17, 21과 호환 - Maven, Gradle 및 모든 JVM 생태계(Kotlin, Scala, Groovy)에서 사용 가능

예시

내장 HttpClient (Java 11+)

Java 11부터 제공되는 표준 라이브러리로, 타사 종속성이 필요 없습니다. ProxySelector를 통해 프록시를 구성하고 Authenticator를 통해 인증 정보를 설정하세요. 동일한 클라이언트를 여러 스레드에서 안전하게 공유할 수 있습니다.

import java.net.*;
import java.net.http.*;
import java.time.Duration;

public class HttpClientExample {
  static final String PROXY_HOST = "p.shifter.io";
  static final int    PROXY_PORT = 443;

  static HttpClient client(String country, String sid) {
    Authenticator auth = new Authenticator() {
      @Override
      protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(
          String.format("customer-USERNAME-country-%s-sid-%s-ttl-300", country, sid),
          "PASSWORD".toCharArray());
      }
    };

    return HttpClient.newBuilder()
      .proxy(ProxySelector.of(new InetSocketAddress(PROXY_HOST, PROXY_PORT)))
      .authenticator(auth)
      .connectTimeout(Duration.ofSeconds(10))
      .build();
  }

  public static void main(String[] args) throws Exception {
    HttpClient c = client("uk", "456DEF");

    for (String path : new String[]{"/login", "/dashboard", "/orders"}) {
      HttpRequest req = HttpRequest.newBuilder()
        .uri(URI.create("https://example.co.uk" + path))
        .header("User-Agent", "Mozilla/5.0 (Windows) AppleWebKit/537.36")
        .timeout(Duration.ofSeconds(30))
        .GET()
        .build();

      HttpResponse<String> r = c.send(req, HttpResponse.BodyHandlers.ofString());
      System.out.println(path + " " + r.statusCode() + " " + r.body().length());
    }
  }
}

OkHttp

OkHttp는 Java에서 가장 널리 쓰이는 HTTP 클라이언트입니다. 클라이언트 빌더에서 프록시와 자격 증명을 설정하세요. 동일한 클라이언트를 여러 스레드에서 안전하게 재사용하며 연결을 멀티플렉싱할 수 있습니다.

import okhttp3.*;
import java.net.InetSocketAddress;
import java.net.Proxy;

public class OkHttpExample {
  public static void main(String[] args) throws Exception {
    Proxy proxy = new Proxy(Proxy.Type.HTTP,
      new InetSocketAddress("p.shifter.io", 443));

    Authenticator proxyAuth = (route, response) -> {
      String credential = Credentials.basic(
        "customer-USERNAME-country-de-city-berlin-sid-789GHI", "PASSWORD");
      return response.request().newBuilder()
        .header("Proxy-Authorization", credential)
        .build();
    };

    OkHttpClient client = new OkHttpClient.Builder()
      .proxy(proxy)
      .proxyAuthenticator(proxyAuth)
      .build();

    Request request = new Request.Builder()
      .url("https://api.example.de/products")
      .header("User-Agent", "Mozilla/5.0 (Linux) AppleWebKit/537.36")
      .build();

    try (Response response = client.newCall(request).execute()) {
      System.out.println(response.code() + " " + response.body().string().length());
    }
  }
}

Selenium WebDriver

JavaScript로 렌더링되는 대상을 위해 Shifter를 통해 실제 Chrome / Firefox 인스턴스를 구동하세요. 프록시 인증을 처리하려면 selenium-wire(또는 Chrome 확장 프로그램)를 사용하세요.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.Proxy;

public class SeleniumExample {
  public static void main(String[] args) {
    Proxy proxy = new Proxy();
    proxy.setHttpProxy("p.shifter.io:443");
    proxy.setSslProxy("p.shifter.io:443");

    ChromeOptions options = new ChromeOptions();
    options.setProxy(proxy);
    options.addArguments("--headless=new");
    options.addArguments(
      "--user-agent=Mozilla/5.0 (Macintosh) AppleWebKit/537.36"
    );

    // For username-password proxy auth, pair this with Shifter's IP
    // whitelist or use selenium-wire — Chrome ignores credentials in
    // headless mode without a sidecar extension.

    WebDriver driver = new ChromeDriver(options);
    try {
      driver.get("https://example.com");
      System.out.println(driver.getTitle());
      System.out.println(driver.getPageSource().length() + " bytes");
    } finally {
      driver.quit();
    }
  }
}

Spring Boot RestTemplate / WebClient

Shifter를 Spring @Configuration으로 감싸서 앱이 주입하는 모든 RestTemplate 또는 WebClient가 프록시를 통해 라우팅되도록 하십시오. Spring 5+ 및 Spring Boot 3과 함께 작동합니다.

import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.client5.http.auth.*;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class ShifterRestConfig {
  @Bean
  public RestTemplate shifterRestTemplate() {
    HttpHost proxy = new HttpHost("http", "p.shifter.io", 443);

    BasicCredentialsProvider creds = new BasicCredentialsProvider();
    creds.setCredentials(
      new AuthScope(proxy),
      new UsernamePasswordCredentials(
        "customer-USERNAME-country-fr-sid-ABC123",
        "PASSWORD".toCharArray()));

    CloseableHttpClient httpClient = HttpClients.custom()
      .setProxy(proxy)
      .setDefaultCredentialsProvider(creds)
      .setDefaultRequestConfig(RequestConfig.custom().build())
      .build();

    HttpComponentsClientHttpRequestFactory factory =
      new HttpComponentsClientHttpRequestFactory(httpClient);

    return new RestTemplate(factory);
  }
}
자주 묻는 질문

자주 묻는 질문

Java와 Shifter 사용에 관한 일반적인 질문.

PasswordAuthentication을 getPasswordAuthentication에 반환하는 Authenticator를 통해 자격 증명을 제공하고, ProxySelector.of(new InetSocketAddress("p.shifter.io", 443))을 HttpClient.newBuilder().proxy(...)에 전달하세요. 표준 라이브러리만 사용하며 추가 의존성이 필요하지 않습니다.

new Proxy(Proxy.Type.HTTP, address)를 사용하여 OkHttpClient.Builder()에 프록시를 설정하고, Credentials.basic(user, pass)를 사용하여 Proxy-Authorization 헤더를 추가하는 proxyAuthenticator를 제공하세요. 동일한 클라이언트를 여러 스레드에서 안전하게 재사용할 수 있습니다.

예. Selenium Proxy 객체에 HTTP 및 SSL 프록시 호스트를 설정하고, 이를 ChromeOptions에 연결한 후 ChromeDriver를 실행하세요. 헤드리스 모드에서 사용자 이름-비밀번호 인증을 사용하려면 Shifter의 IP 화이트리스트와 함께 사용하거나 selenium-wire를 사용하세요. Chrome은 기본적으로 프록시 자격 증명을 입력받는 프롬프트를 제공하지 않습니다.

프록시 사용자 이름에 세션 ID를 추가하세요(예: `customer-USERNAME-country-us-sid-123ABC`). 동일한 sid로 인증하는 모든 요청은 동일한 레지덴셜 IP를 재사용합니다. `ttl-N`을 추가하면 해당 IP를 최대 N초 동안 고정할 수 있습니다.

예. Apache HttpClient 또는 Reactor Netty 클라이언트를 Shifter를 프록시로 감싸는 RestTemplate 또는 WebClient @Bean을 구성하세요. 외부 API를 호출해야 하는 곳마다 해당 빈을 주입하면 됩니다. Spring Framework 5 이상과 Spring Boot 3에서 작동합니다.

SDK가 필요하지 않습니다. Shifter는 일반 HTTP / SOCKS5를 사용하므로, 기존 클라이언트를 `p.shifter.io:443`으로 지정하면 됩니다. 이렇게 하면 pom.xml 또는 build.gradle이 간결해지고 Java 8부터 Java 21까지 작동합니다.

시작하기

Shifter 사용을 함께 시작하기 Java

5분 이내에 Shifter의 205M+ 레지덴셜 및 ISP 프록시를 JVM 스택에 추가하세요. HttpClient, OkHttp, Spring, Selenium WebDriver와 함께 작동합니다.

Shifter 무료로 체험하기몇 분 만에 설정. 언제든지 취소 가능.