那里可以建网站,wordpress 评论 样式,仿所有网站,做网站第一次见客户我们使用Java的RestTemplate或者Apache的HTTPClient编程的时候#xff0c;经常遇到需要跟踪Java代码发送的HTTP请求明细的情况。和javascript代码在浏览器里发送请求可以通过Chrome开发者工具方便地跟踪一样#xff0c;对于Java代码发送的网络请求#xff0c;我们也可以使用…我们使用Java的RestTemplate或者Apache的HTTPClient编程的时候经常遇到需要跟踪Java代码发送的HTTP请求明细的情况。和javascript代码在浏览器里发送请求可以通过Chrome开发者工具方便地跟踪一样对于Java代码发送的网络请求我们也可以使用工具Fiddler来监控。打开Fiddler在connections面板里找到Fiddler监听的端口号8888如果是使用Apache的HTTPClient进行网络请求发送代码如下使用HttpHost设置请求代理private static void downloadCommerce(){HttpHost proxy  new HttpHost(localhost, 8888, http);RequestConfig config  RequestConfig.custom().setProxy(proxy).build();CloseableHttpClient client HttpClientBuilder.create().setDefaultRequestConfig(config).build();String url  https://jerrywang.com:9002/rest/v2/electronics/users/jerry.wangsap.com;String token  test;    HttpGet get  new HttpGet(url);    get.setHeader(Authorization, Bearer   token);        try {            HttpResponse response  client.execute(get);            HttpEntity entity  response.getEntity();            String result  EntityUtils.toString(entity, UTF-8);            System.out.println(url:   result);        } catch (Exception e){        e.printStackTrace();        }}执行Java应用然后到Fiddler里看到了监控到的HTTP请求各种明细比如Java代码里硬编码的OAuth 2的认证token testJava代码收到的服务器端返回的错误消息这个错误消息在Fiddler里当然也是可以看到的在这种场景里Fiddler扮演的就是类似Chrome开发者工具的角色。