1

Somehow Fiddler doesn't capture the posts I send from my HttpClient provided by Apache.

But when I send the same post in C# using the HttpClient to the same server, Fiddler does intercept the sessions.

My Java code:

private DefaultHttpClient client = new DefaultHttpClient();
private HttpContext context = new BasicHttpContext();
private BasicCookieStore store = new BasicCookieStore();

public Client() throws URISyntaxException {
    context.setAttribute(ClientContext.COOKIE_STORE, store);
    logIn();
}

private void logIn() throws URISyntaxException {
    HttpUriRequest login = RequestBuilder.post()
            .setUri(new URI("http://www.derpforum.nl"))
            .addParameter("username", "Kattoor4")
            .addParameter("password", "XXXX")
            .addHeader("Referer", "http://www.derpforum.nl/")
            .build();
    try (CloseableHttpResponse response = client.execute(login, context)) {
        HttpEntity entity = response.getEntity();
        BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
        String line;
        while ((line = reader.readLine()) != null)
            System.out.println(line);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Any thoughts? Thanks!

f_puras
  • 2,521
  • 4
  • 33
  • 38
Jasper Catthoor
  • 595
  • 1
  • 6
  • 22

2 Answers2

1

I am usring Apache HttpClient(4.5.5), SWT4 and Fiddler4, and the VM arguments method does not work for me.

So I set the proxy settings in the code and it works.

HttpHost proxy = new HttpHost("localhost", 8888, "http");
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
CloseableHttpClient httpclient = HttpClients.custom()
                .setRoutePlanner(routePlanner)
                .build();
ZhaoGang
  • 4,491
  • 1
  • 27
  • 39
0

You probably need to configure Java to use Fiddler as a proxy either in code or by setting the relevant Java system properties as below. See this question.

-Dhttp.proxyHost=127.0.0.1
-Dhttp.proxyPort=8888
Community
  • 1
  • 1
Nick Westgate
  • 3,088
  • 2
  • 34
  • 41