1.设置代理ip
1 HttpHost proxy = new HttpHost("112.36.34.134",80);//设置代理ip 2 3 RequestConfig config = RequestConfig.custom() 4 .setProxy(proxy) 5
2.延长访问时间
1 RequestConfig config = RequestConfig.custom() 2 3 .setConnectTimeout(1000=0)// 创建连接的最长时间 4 .setConnectionRequestTimeout(1000)// 获取连接的最长时间 5 .setSocketTimeout(1000)// 数据传输的最长时间 6 .build();
3.伪装成浏览器
1 HttpGet httpGet = new HttpGet(url); 2 // 设置请求信息 3 //伪装浏览器 4 httpGet.setHeader("User-Agent","Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0");