Last active
September 5, 2023 10:56
-
-
Save hihanley/273afa9ba20420bad918275075981240 to your computer and use it in GitHub Desktop.
Java okhttp 请求设置代理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.net.InetSocketAddress; | |
import java.net.Proxy; | |
import okhttp3.OkHttpClient; | |
import okhttp3.Request; | |
public class Demo{ | |
public static void main(String[] args) throws IOException { | |
var proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 1080)); | |
var client = new OkHttpClient.Builder().proxy(proxy).build(); | |
var request = new Request.Builder().url("https://ipinfo.io/json").get().build(); | |
System.out.println(client.newCall(request).execute().body().string()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment