【问题标题】:Getting information about the system proxy获取有关系统代理的信息
【发布时间】:2012-01-11 16:25:18
【问题描述】:

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

DefaultHttpClient httpclient = new DefaultHttpClient();

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

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

【问题讨论】:

    标签: android proxy


    【解决方案1】:

    试试这个:

    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

    【讨论】:

      猜你喜欢
      • 2014-07-24
      • 2018-06-07
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2018-12-11
      • 2014-10-09
      相关资源
      最近更新 更多