0

I want to configure Burp as a proxy for my java code, to see requests and responses. Burp works fine as a proxy between a web browser, but it doesn't for java application.

I've added to my code such lines:

WebClient client = new WebClient();
System.setProperty("https.proxyHost", "127.0.0.1");
System.setProperty("https.proxyPort", "8081");
client.getOptions().setCssEnabled(false);
client.getOptions().setJavaScriptEnabled(false);
client.getCookieManager().setCookiesEnabled(true);
URL url = new URL("https://www.google.com");
WebRequest request =   new WebRequest(url, HttpMethod.GET);
Page page = client.getPage(request);

And configured Burp to listen on 8081 port.

Should I do anything else?

Laucer
  • 31
  • 5
  • 1
    Could you please post a Java code snippet which shows what you want to do in your application. – SubOptimal Sep 14 '18 at 14:07
  • Thanks for response. I've edited my post. In Burp I also set -> Proxy -> Options -> Add -> Bind to port 8081 – Laucer Sep 16 '18 at 16:30

1 Answers1

2

Where it is working for plain Java as

System.setProperty("http.proxyHost", "127.0.0.1");
System.setProperty("http.proxyPort", "8081");
URL url = new URL("http://example.com");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.getHeaderFields()
        .forEach((key, value) -> System.out.printf("%s: %s%n", key, value));
con.disconnect();

you need to configure the proxy differently for htmlunit. One possible way would be to set it with webClientOptions.setProxyConfig(proxyConfig)

WebClient client = new WebClient();
ProxyConfig proxyConfig = new ProxyConfig("127.0.0.1", 8081);
WebClientOptions options = client.getOptions();
options.setProxyConfig(proxyConfig);
URL url = new URL("http://example.com");
WebRequest request =   new WebRequest(url, HttpMethod.GET);
Page page = client.getPage(request);
page.getWebResponse().getResponseHeaders().forEach(System.out::println);
client.close();
SubOptimal
  • 22,518
  • 3
  • 53
  • 69