java 模拟代理http请求

public  void httpWithproxy(String ip, int port,String url) {

		HttpHost proxy = new HttpHost(ip, port);
		RequestConfig config = RequestConfig.custom()
								.setProxy(proxy)
								.setConnectionRequestTimeout(1000 * 10)
								.setConnectTimeout(1000 * 10)
								.setSocketTimeout(1000 * 10)
								.build();
		CloseableHttpClient httpclient=HttpClients.createDefault();
		HttpGet httpget=new HttpGet(url);
		httpget.setConfig(config);
		HttpResponse response;
		try {
			response=httpclient.execute(httpget);
			System.out.println(EntityUtils.toString(response.getEntity(),"UTF-8"));
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

猜你喜欢

转载自blog.csdn.net/caideb/article/details/81352867