Oct 28, 2013
Oct 28, 2013
N/A Views
MD
warning
この記事は2年以上前に更新されたものです。情報が古くなっている可能性があります。

いつも忘れるのでメモ

package sample;

import java.net.Authenticator;
import java.net.PasswordAuthentication;

import org.springframework.web.client.RestTemplate;

public class Main {

    static {
        System.setProperty("http.proxyHost", "proxy host");
        System.setProperty("http.proxyPort", "port");
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("domain\\username", "password"
                        .toCharArray());
            }
        });
    }

    public static void main(String[] args) {
        RestTemplate template = new RestTemplate();
        System.out.println(template.getForEntity("http://google.com",
                String.class));
    }
}
Found a mistake? Update the entry.
Share this article: