很简单,直接上代码
public static void main(String[] args) throws Exception {
String url = "http://www.baidu.com";//需要访问的地址
//("127.0.0.1",18081) 代理地址与端口
OkHttpClient client = new Builder().proxy(new Proxy(Type.HTTP,new InetSocketAddress("127.0.0.1",18081)))
.readTimeout(1000L, TimeUnit.MINUTES).build();
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
String str = response.body().string();
System.out.println(str);
}
}