获取有关系统代理信息 [英] Getting information about the system proxy

查看:210
本文介绍了获取有关系统代理信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的HttpClient 在我的Andr​​oid应用程序。有些用户可以拥有自己的设备上配置系统代理。我如何获得这些信息?
从这个<一个href=\"http://stackoverflow.com/questions/4503437/android-httpclient-doesnt-use-system-proxy-settings\">answer我知道你可以这样做:

I'm using HttpClient on my android application. Some user can have a system proxy configured on his device. How do I get the information? From this answer I know you can do something like:

DefaultHttpClient httpclient = new DefaultHttpClient();

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

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

The problem is that I don't know where to find hostname of the proxy and the port.

推荐答案

试试这个:

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);
}

我没有测试过。这里发现

I did not test through. Found here.

这篇关于获取有关系统代理信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆