Last active
July 6, 2020 14:21
-
-
Save jamesdixon/f9febc4f76cf3229815e46ed50b75d22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 HttpClient instance. | |
HttpClient httpClient = new HttpClient(); | |
// Hook into the findProxy callback to set | |
// the client's proxy. | |
httpClient.findProxy = (uri) { | |
return "PROXY $proxy;"; | |
}; | |
// This is a workaround to allow Charles to receive | |
// SSL payloads when your app is running on Android. | |
httpClient.badCertificateCallback = | |
((X509Certificate cert, String host, int port) => Platform.isAndroid); | |
// Pass your newly instantiated HttpClient to http.IOClient. | |
IOClient myClient = IOClient(httpClient); | |
// Make your request as normal. | |
var response = myClient.get('/my-url'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment