Search code examples
intellij-ideaproxycharles-proxy

How do I hook up Charles with IntelliJ?


I am writing a web application in Java using IntelliJ, and I would like to monitor all my http/https requests using Charles, however my requests do not show up by default, so I am suspecting that some proxy settings need to be set up on both sides. Can someone explain it in details? Thanks a lot in advance!


Solution

  • Ok so, I have managed to understand the problem and also solve it.

    JVM proxy

    The first issue was that my requests were essentially coming from the JVM, so that's why we have to proxy them first, which means a JVM configuration has to be made, which can be provided as arguments (can be provided through CLI or under VM options in IntelliJ) like so:

    -DproxySet=true -DproxyHost=127.0.0.1 -DproxyPort=8888

    HTTPS

    The next issue was that along with this proxy, certificates also have to be provided in order to capture and view decrypted https requests.

    We can generate Fiddler certificates by going to Tools > Options > HTTPS > Decrypt HTTPS traffic. The generated cert can be downloaded from http://127.0.0.1:8888/.

    Using JVM's keytool, we can create a new keystore using our certificate, which we can use later as a JVM configuration to trust resources. To do so, run the following command (make sure to provide the right paths for the keytool and the cert):

    "C:\Program Files\Java\jdk1.8.0_144\bin\keytool.exe -import -file C:\Users\Username\Desktop\FiddlerRoot.cer -keystore FiddlerKeystore -alias Fiddler After providing a password, the keystore will be generated at C:\Windows\System32.

    Now, we can provide this keystore and password to the JVM by passing the following:

    -Djavax.net.ssl.trustStore="C:\Windows\System32\FiddlerKeystore" -Djavax.net.ssl.trustStorePassword="yourKeyStorePassword"

    This answer was based on the following blog post and StackOverflow answer: