When I create a DefaultHttpClient object and try to hit a webpage, the request isn't routed through the proxy I specified in Settings.
Looking through the API docs, I don't see anywhere where I can specify a proxy though Android does have a Proxy class that allows me to read the system's proxy settings.
Is there a way I can use the proxy settings in an HttpClient?
No, they do not apply globally and without root there is no way to force a proxy to be used by all applications. The reason the message you found is worded that way is that it is up to the app creator to respect the proxy settings and use them or do the wrong thing and ignore them.
What Does HTTP Proxy Mean? An HTTP Proxy serves two intermediary roles as an HTTP Client and an HTTP Server for security, management, and caching functionality. The HTTP Proxy routes HTTP Client requests from a Web browser to the Internet, while supporting the caching of Internet data.
Proxies serve as intermediary connection points between HTTP clients and web servers that add security and privacy to internet connections. To support running Android Studio behind a firewall, set the proxy settings for the Android Studio IDE.
Try:
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpHost proxy = new HttpHost("someproxy", 8080);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
(culled from here)
Firstly, I would make sure that the request is adhering to the proxy settings properties you set in the Android Device's settings. You can determine this via code by looking at the System class in android.provider.Settings;
To identify if the user had system proxy settings, you can do the following:
System.getProperty("http.proxyHost");
System.getProperty("http.proxyPort");
System.getProperty("https.proxyHost");
System.getProperty("https.proxyPort");
If you have an instance of DefaultHTTPClient, then you can check whether it has the relevant proxy settings as well.
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().getParameter(ConnRoutePNames.DEFAULT_PROXY);
These are all ways to 'get' the proxy settings, and the 'set' methods are implemented in the same way, either through System.setProperty or httpclient.setParams.
Hope this helped!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With