Flutter app not using Fiddler proxy

2,951

Solution 1

I did some more tests with Drony and I got it to work. Still one problem, I couldn't send HTTPS requests anymore since Dart/Flutter doesn't have an easy way to trust all SSL certificates. I could debug HTTP requests at this point.

My API only support HTTPS requests, so in my Flutter app I request the HTTP version and I forward it to the HTTPS API via Fiddler: (following code goes in the OnBeforeRequest function)

    if (!oSession.isHTTPS && oSession.HostnameIs("api.xxxx.me")){
        oSession.fullUrl = "https://" + "api.xxxx.me" + oSession.PathAndQuery;
    }

Solution 2

In general, if you're facing this issue it's means that your Flutter application is either ignoring the system proxy settings for some reason, or that it doesn't trust Fiddler's HTTPS certificate.

You can usually tell the difference by using the app and checking its logs: if the app works OK and the logs are fine, it's probably ignoring Fiddler entirely. If the app can't connect to the internet, especially if there are security/TLS/certificate warnings in logcat, then it probably doesn't trust the certificate.

If the proxy isn't trusted, you need to either do that in your code, or use configure a separate app that can force proxy settings for you by acting as a VPN. If the certificate isn't trusted, you'll need to configure that in your app's network security settings.

Fiddler isn't really a great option for Android though. You might have better luck with a tool with Android support built-in - I've been building exactly that, it's an open-source project called HTTP Toolkit which can do this for all Android apps, including anything built with Flutter:

enter image description here

It does all the VPN proxy-enforcing work for you, with one-click setup and no code changes, and it can automatically handle certificate setup too (even system-level certificates, on emulators & rooted devices). That should remove both ways you can get into this situation.

Otherwise it's very similar to Fiddler: an intercepting proxy that lets you inspect & rewrite HTTPS from any clients you like.

Solution 3

I was able to get Charles Proxy to work with HttpClient using the following snippets:

localhost can be the ip address for your computer like 192.168.1.77

HttpClient client = HttpClient();
client.findProxy = (uri) {
  return "PROXY localhost:3128;";
};

A more full implementation:

  static HttpClient getHttpClient() {
    HttpClient client = new HttpClient()
      ..findProxy = (uri) {
        return "PROXY 192.168.1.199:8888;";
      }
      ..badCertificateCallback =
      ((X509Certificate cert, String host, int port) => true);

    return client;
  }

More information and solution for other HTTP clients can also be found here:

https://github.com/flutter/flutter/issues/20376

Share:
2,951
Nathan
Author by

Nathan

Python Developer.

Updated on December 04, 2022

Comments

  • Nathan
    Nathan over 1 year

    I just started playing around with Flutter, and am now trying to do some simple HTTP(s) requests. I've always used Fiddler with proxy to debug requests send from android apps, but the requests send from Flutter don't seem to show.

    Is there any way I can get Fiddler to show Flutter requests, or is there some other HTTP Requests debugging tool/monitor I can/should use?

  • Cyrus the Great
    Cyrus the Great over 3 years
    I installed it on my linux pc and android emulator. It not shows any of network requests on my flutter app like fiddler
  • Tim Perry
    Tim Perry over 3 years
    That's very surprising! Is it running on the Android emulator, and showing as connected there? What emulator and OS version are you using? Feel free to send an email to [email protected] with more details and I'll investigate.