Skip to content

Instantly share code, notes, and snippets.

@jamesdixon
Last active July 6, 2020 14:21
Show Gist options
  • Select an option

  • Save jamesdixon/f9febc4f76cf3229815e46ed50b75d22 to your computer and use it in GitHub Desktop.

Select an option

Save jamesdixon/f9febc4f76cf3229815e46ed50b75d22 to your computer and use it in GitHub Desktop.

Revisions

  1. jamesdixon revised this gist Sep 4, 2019. 1 changed file with 11 additions and 10 deletions.
    21 changes: 11 additions & 10 deletions http-proxy.dart
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,24 @@
    // make sure to replace <YOUR_LOCAL_IP> with
    // the external IP of your computer.
    String proxy = '<YOUR_LOCAL_IP>:8888';
    // 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
    // Create a new HttpClient instance.
    HttpClient httpClient = new HttpClient();

    // hook into the findProxy callback to set
    // the client's proxy
    // 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
    // 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
    // Pass your newly instantiated HttpClient to http.IOClient.
    IOClient myClient = IOClient(httpClient);

    // make your request as normal
    // Make your request as normal.
    var response = myClient.get('/my-url');
  2. jamesdixon created this gist Aug 30, 2019.
    23 changes: 23 additions & 0 deletions http-proxy.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    // make sure to replace <YOUR_LOCAL_IP> with
    // the external IP of your computer.
    String proxy = '<YOUR_LOCAL_IP>: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');