简体   繁体   中英

how to use proxy for HTTP connection on android?

The usual java way doesnt seem to work - i put in bogus values in there and it still "works", so it seems that android doesnt read those properties. I also put this info into Settings section of OS (via GUI). ANy ideas? Thx.

    Properties props = System.getProperties();
    props.put("http.proxyHost", "190.128.1.69");
    props.put("http.proxyPort", "80"); 

Two ways to do it.

System.setProperty("http.proxyHost", <your proxy host name>);
System.setProperty("http.proxyPort", <your proxy port>);

or

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpHost httpproxy = new HttpHost("<your proxy host>",<your proxy port>);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, httpproxy);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM