Laucer
Laucer

Reputation: 31

Java Proxy Burp

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?

Upvotes: 0

Views: 772

Answers (1)

SubOptimal
SubOptimal

Reputation: 22963

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();

Upvotes: 2

Related Questions