Skip to content

Instantly share code, notes, and snippets.

@twaddington
Last active June 22, 2022 06:06
Show Gist options
  • Save twaddington/6ba44e4f8d74f40ab0d973e1af040d9b to your computer and use it in GitHub Desktop.
Save twaddington/6ba44e4f8d74f40ab0d973e1af040d9b to your computer and use it in GitHub Desktop.
mitmproxy with Java and OkHttp

Add cert to Java keystore

sudo keytool -import -trustcacerts -cacerts -storepass changeit -alias mitmproxycert -file ~/.mitmproxy/mitmproxy-ca-cert.pem

Configure OkHttp

private val mitmProxy =
  Proxy(Proxy.Type.HTTP, InetSocketAddress("127.0.0.1", 8080))

private val okhttp =
  OkHttpClient.Builder()
    .addInterceptor(httpLogging)
    .proxy(mitmProxy)
    .build()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment