如何通过抓包工具fiddler获取java程序的http请求

就是要在请求的时候,设置代理

Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP,new InetSocketAddress("127.0.0.1", 8888));
URL serverUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) serverUrl.openConnection(proxy);

用RestTemplate的时候,设置代理

RestTemplate restTemplate = new RestTemplate(new SimpleClientHttpRequestFactory() {
    {
        setProxy(new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8888)));
    }});

或者直接在类中的方法添加

System.setProperty("http.proxyHost", "127.0.0.1");
System.setProperty("https.proxyHost", "127.0.0.1");
System.setProperty("http.proxyPort", "8888");
System.setProperty("https.proxyPort", "8888");

 

你可能感兴趣的:(java)