Fiddler not capturing HTTP requests from Java Application

23,144

Solution 1

You can simply set Fiddler as HTTP proxy for your application by setting the properties

http.proxyHost to localhost and http.proxyPort to 8888 for HTTP traffic and https.proxyHost / https.proxyPort for HTTPS traffic. For HTTPS traffic you also have to add the Fiddler root certificate (exportable in options dialog) as trusted certificate to your application.

You can do so by adding the following lines at the beginning of your code

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

or set them via command line when starting the Java-VM:

java -Dhttp.proxyHost=localhost -Dhttp.proxyPort=8888 ...

Solution 2

With Jetty HTTP client, the previous solution doesn't work. The following works however:

HttpClient httpClient = new HttpClient();
httpClient.setProxy(new Address("127.0.0.1", 8888));
httpClient.start();
Share:
23,144

Related videos on Youtube

Andrew
Author by

Andrew

.Net developer for work. OSX developer for fun.

Updated on October 22, 2020

Comments

  • Andrew
    Andrew over 3 years

    I am currently writing a java application that uses HTTP POST to upload a csv file and a few other parameters to a server. The server keeps returning 500 errors to my application and I would like to view the HTTP request in Fiddler so I can see the POST request.
    When I run Fiddler it will not capture any HTTP traffic from the Java application. I have written a GET request that works, so I know I can communicate with the server, however no traffic is shown through Fiddler.

    • CFL_Jeff
      CFL_Jeff about 12 years
      Is there a Java Servlet processing the post?
    • matcheek
      matcheek about 12 years
      are you sure it is not https traffic?
    • Andrew
      Andrew about 12 years
      There is not. I am using Apache's HTTPComponents to call an upload method from an API on the server.
    • Andrew
      Andrew about 12 years
      @matcheek It is HTTPS traffic. Can this be captured through Fiddler?
    • matcheek
      matcheek about 12 years
  • Andrew
    Andrew about 12 years
    The development server I am writting against uses a self signed certificate so I have written classes to trust all certificates. I have set the proxyHost and proxyPort properties, however I am still not seeing any traffic from the application through Fiddler.
  • Andrew
    Andrew about 12 years
    I was able to get this to work by using https in the properties and changing the local host to 127.0.0.1.
  • Andrew
    Andrew about 12 years
    My change made it possible to view the HTTP GET request that uses HttpURLConnection. The POST request is using Apache's HttpComponents and I cannot see this traffic, still.
  • Robert
    Robert about 12 years
    @Andrew Using two independent technologies does not sound like a good design of your app (doubles the chance of problems). Anyway you can set the proxy in the apache http client: hc.apache.org/httpcomponents-client-ga/httpclient/examples/o‌​rg/…