OKhttpclient 使用代理访问服务
生活随笔
收集整理的這篇文章主要介紹了
OKhttpclient 使用代理访问服务
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
很簡單,直接上代碼
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);} }總結
以上是生活随笔為你收集整理的OKhttpclient 使用代理访问服务的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 喷血之举--割肉之痛
- 下一篇: 什么叫无线网络