首页 > 编程语言 > 详细

通过Fiddler抓取Java HttpClient的HTTP包

时间:2017-11-11 18:29:19      阅读:744      评论:0      收藏:0      [点我收藏+]

设置HttpClient访问Fiddler的代理即可。

public static void main(String[] args) throws Exception {
        
        HttpPost httpPost = new HttpPost("xxx");
        
        HttpHost proxy = new HttpHost("127.0.0.1",8888);
        RequestConfig requestConfig = RequestConfig.custom().setProxy(proxy).build();
        CloseableHttpClient httpclient= HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
        
        HttpResponse httpResponse = httpclient.execute(httpPost);
        int statusCode = httpResponse.getStatusLine().getStatusCode();

        System.out.println(httpResponse.getStatusLine());

        String result = null;

        if (statusCode == HttpStatus.SC_OK) {
            HttpEntity resEntity = httpResponse.getEntity();
            result = EntityUtils.toString(resEntity);
        }

        httpclient.getConnectionManager().shutdown();
        
        System.out.println("result:"+result);
    }

 

通过Fiddler抓取Java HttpClient的HTTP包

原文:http://www.cnblogs.com/yshyee/p/7819502.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!