wireshark抓包简单查看HTTP keep |
您所在的位置:网站首页 › wireshark怎么抓pppoe协议包 › wireshark抓包简单查看HTTP keep |
HTTP keep-alive
要利用HTTP的keep-alive机制,需要服务器端和客户端同时支持,以下使用tomcat服务器(支持keep-alive),使用wireshark抓包测试几种客户端是否支持keep-alive 使用chrome浏览器作为客户端 往浏览器地址栏敲入http://localhost:8080/user/object?name=ds&id=2&,并刷新一次抓包结果如下:Java代码如下: package edu.kxw; import java.io.IOException; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.clienthods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import org.junit.Test; /** * Created by kingsonwu on 17/5/18. */ public class TestHttpKeepAliveClient { @Test public void testHeader() throws InterruptedException { String url = "http://localhost:8080/user/object?name=ds&id=2&"; //创建HttpClientBuilder HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); //HttpClient CloseableHttpClient closeableHttpClient = httpClientBuilder.build(); HttpGet httpGet = new HttpGet(url); httpGet.addHeader("Connection", "keep-alive"); try { //执行get请求 HttpResponse httpResponse = closeableHttpClient.execute(httpGet); //获取响应消息实体 HttpEntity entity = httpResponse.getEntity(); //响应状态 System.out.println("status:" + httpResponse.getStatusLine()); //判断响应实体是否为空 if (entity != null) { System.out.println("contentEncoding:" + entity.getContentEncoding()); String content = EntityUtils.toString(entity); System.out.println("response content:" + content); } Thread.sleep(5000); closeableHttpClient.execute(httpGet); } catch (IOException e) { e.printStackTrace(); } finally { try { //关闭流并释放资源 closeableHttpClient.close(); } catch (IOException e) { e.printStackTrace(); } } } }抓包结果如下: 程序发请求时带上请求头keep-alive(不加也行), 并休眠5秒后重新发送请求,从抓包结果中看,复用了连接。 reference: wireshark使用:http://blog.jobbole.com/70907/ ,https://my.oschina.net/flashsword/blog/80037 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |