'How to use proxies library in flutter?
I want to create an Android app that connects to a proxy by button clicked and I'd like to know what should do to make this event?
My proxy needs(password, username, host, port).
I would be appreciated if you help me with this problem .
Solution 1:[1]
Add DIO settings like this
String proxy = '<IP>:<PORT>'; //eg 192.168.1.1:8080
var credentials = HttpClientBasicCredentials(<USERNAME>, <PASSWORD>);
bool isProxyChecked = true;
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
(client) {
client.badCertificateCallback = (X509Certificate cert, String host, int port) {
return isProxyChecked && Platform.isAndroid;
};
client.findProxy = (url) {
return isProxyChecked ? 'PROXY $proxy' : 'DIRECT';
};
client.addProxyCredentials(<PROXY_IP>, <PORT>, 'main', credentials);
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | sibin |