2012-01-11 73 views
0

我在我的android应用程序上使用HttpClient。某些用户可以在他的设备上配置系统代理。我如何获取信息? 从这个answer我知道你可以这样做:获取有关系统代理的信息

DefaultHttpClient httpclient = new DefaultHttpClient(); 

HttpHost proxy = new HttpHost("someproxy", 8080); 
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); 

的问题是,我不知道在哪里找到的代理和端口的主机名。

回答

0

试试这个:

DefaultHttpClient httpclient = new DefaultHttpClient(); 

String proxyString = Settings.Secure.getString(getApplicationContext().getContentResolver(), Settings.Secure.HTTP_PROXY); 

if (proxyString != null) 
{ 
    String proxyAddress = proxyString.split(":")[0]; 
    int proxyPort = Integer.parseInt(proxyString.split(":")[1]); 
    HttpHost proxy = new HttpHost(proxyAddress, proxyPort); 

    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); 
} 

我没有测试过。找到here