0

我正在android上开发一个应用程序,公司中有一个代理服务器阻止它访问互联网。
我记得java中有用于此目的的Http方法,我搜索了它们但没有结果。

所以我想要的是如何放置服务器 IP 地址和端口号,以及我的登录用户名和密码,以及域名。

注意:我已将我的模拟器设置为通过访问 APNs 连接到互联网,它通过浏览器成功连接到互联网。

4

1 回答 1

0

尝试使用以下代码

/**
 * A simple example that uses HttpClient to execute an HTTP request
 * over a secure connection tunneled through an authenticating proxy.
 */
public class ClientProxyAuthentication {

    public static void main(String[] args) throws Exception {

        DefaultHttpClient httpclient = new DefaultHttpClient();
        try {
            httpclient.getCredentialsProvider().setCredentials(
                    new AuthScope("localhost", 8080),
                    new UsernamePasswordCredentials("username", "password"));

            HttpHost targetHost = new HttpHost("www.verisign.com", 443, "https");
            HttpHost proxy = new HttpHost("localhost", 8080);

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

            HttpGet httpget = new HttpGet("/");

            System.out.println("executing request: " + httpget.getRequestLine());
            System.out.println("via proxy: " + proxy);
            System.out.println("to target: " + targetHost);

            HttpResponse response = httpclient.execute(targetHost, httpget);
            HttpEntity entity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (entity != null) {
                System.out.println("Response content length: " + entity.getContentLength());
            }
            EntityUtils.consume(entity);

        } finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }
    }
}
于 2011-12-11T08:11:12.873 回答