Heim > Fragen und Antworten > Hauptteil
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(100);
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build();
HttpGet getMethod = new HttpGet("https://www.zomato.com/ncr");
getMethod.addHeader("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
getMethod.addHeader("accept", "text/html");
getMethod.addHeader("accept-encoding", "gzip");
getMethod.addHeader("accept-language", "zh-CN");
CloseableHttpResponse execute = httpClient.execute(getMethod);
System.out.println(execute.getEntity().getContent());
HttpClient client = new HttpClient();
GetMethod getMethod = new GetMethod("https://www.zomato.com/ncr");
getMethod.addRequestHeader("user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
getMethod.addRequestHeader("accept", "text/html");
getMethod.addRequestHeader("accept-encoding", "gzip");
getMethod.addRequestHeader("accept-language", "zh-CN");
int i = client.executeMethod(getMethod);
System.out.println(i);
byte[] responseBody = getMethod.getResponseBody();
System.out.println(responseBody.length);
为什么方式一请求无响应,如何解决
方式一与方式二在发送请求时有什么区别