Fiddler 抓取 Java HttpClient发送的请求

发布时间 2023-05-05 02:36:53作者: 假装空白

设置代理即可

        
/**
* 设置代理
* hostnameFiddler所处IP地址
* portFiddler监听端口
*/
HttpHost proxy = new HttpHost("127.0.0.1", 8888); RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).build(); // CloseableHttpClient httpClient = HttpClients.createDefault(); String url = "http://www.baidu.com/"; HttpGet httpGet = new HttpGet(url); CloseableHttpResponse response = client.execute(httpGet); String s = EntityUtils.toString(response.getEntity(), "UTF-8"); System.out.println(s);