質問

いを取り出し、SSLページJava.問題は、この認証に対するhttpプロキシ.

きたいと思っていましたが簡単に取得します。またApache Commons httpclientでも架私の問題です。

またこの作品のコードが含まれていません認証アクション:

import java.io.*;
import java.net.*;

public class ProxyTest {

  public static void main(String[] args) throws ClientProtocolException, IOException {

    URL url = new URL("https://ssl.site");
    Socket s = new Socket("proxy.address", 8080);
    Proxy proxy = new Proxy(Proxy.Type.HTTP, s.getLocalSocketAddress());

    URLConnection connection = url.openConnection(proxy);
    InputStream inputStream = connection.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
    String tmpLine = "";

    while ((tmpLine = br.readLine()) != null) {
      System.out.println(tmpLine);
    }

  }
}

誰でもできるので様の情報をどのように実践できるように簡単です。

かまいません。

役に立ちましたか?

解決

org.apache.commons.httpclient.HttpClientはあなたの友人である、

http://hc.apache.org/httpclient-から

サンプルコード3.xの/ sslguide.htmlする

  HttpClient httpclient = new HttpClient();
  httpclient.getHostConfiguration().setProxy("myproxyhost", 8080);
  httpclient.getState().setProxyCredentials("my-proxy-realm", " myproxyhost",
  new UsernamePasswordCredentials("my-proxy-username", "my-proxy-password"));
  GetMethod httpget = new GetMethod("https://www.verisign.com/");
  try { 
    httpclient.executeMethod(httpget);
    System.out.println(httpget.getStatusLine());
  } finally {
    httpget.releaseConnection();
  }

他のヒント

あなたはのjavaを設定する必要があります。 net.Authenticator に、あなたの接続をオープンする前に:

...

public static void main(String[] args) throws Exception {
    // Set the username and password in a manner which doesn't leave it visible.
    final String username = Console.readLine("[%s]", "Proxy Username");
    final char[] password = Console.readPassword("[%s"], "Proxy Password:");

    // Use a anonymous class for our authenticator for brevity
    Authenticator.setDefault(new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });

    URL url = new URL("https://ssl.site");
    ...
}
あなたが終わった後、

あなたのオーセンティケータを削除するには、次のコードを呼び出します:

Authenticator.setDefault(null);

のJava SE 6でのオーセンティケータはHTTP BasicHTTP Digest およびNTLMをサポートしています。詳細については、 HTTP認証ドキュメント>

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top