通过Fiddler抓取Java HttpClient的HTTP包
Posted YSHY
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过Fiddler抓取Java HttpClient的HTTP包相关的知识,希望对你有一定的参考价值。
设置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包的主要内容,如果未能解决你的问题,请参考以下文章
Fiddler 抓取 Java HttpClient发送的请求