Skip to content

Instantly share code, notes, and snippets.

@jamesdixon
Last active July 6, 2020 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamesdixon/c9a807f607066bb4b19ad51416d72ba2 to your computer and use it in GitHub Desktop.
Save jamesdixon/c9a807f607066bb4b19ad51416d72ba2 to your computer and use it in GitHub Desktop.
// Make sure to replace <YOUR_LOCAL_IP> with
// the external IP of your computer if you're using Android.
// Note that we're using port 8888 which is Charles' default.
String proxy = Platform.isAndroid ? '<YOUR_LOCAL_IP>:8888' : 'localhost:8888';
// Create a new Dio instance.
Dio dio = Dio();
// Tap into the onHttpClientCreate callback
// to configure the proxy just as we did earlier.
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
// Hook into the findProxy callback to set the client's proxy.
client.findProxy = (url) {
return 'PROXY $proxy';
};
// This is a workaround to allow Charles to receive
// SSL payloads when your app is running on Android.
client.badCertificateCallback = (X509Certificate cert, String host, int port) => Platform.isAndroid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment