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 に答える