在Android中编程设置代理用户名和密码

3

目前我正在开发一个应用程序,想向代理服务器发送请求。我找到了以下设置代理的代码:

HttpHost httpproxy = new HttpHost("ip",8080);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, httpproxy);

现在我想设置用户名和密码。有人知道如何为代理设置用户名和密码吗?

1个回答

0

为此,您必须使用凭据:

DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope("PROXY HOST", 8080),
new UsernamePasswordCredentials("your_username", "your_password"));
HttpHost targetHost = new HttpHost("TARGET HOST", 443, "https");
HttpHost proxy = new HttpHost("PROXY HOST", 8080);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

但在我看来,那是一种非常不安全的方式!你必须在你的安卓客户端上保存密码。这对于一个脚本小子来说很容易确定密码。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接