This topic describes how to configure a proxy in the V1.0 SDK.
You can use the following variables to configure a proxy:
HTTP_PROXY or http_proxy
HTTPS_PROXY
NO_PROXY
You can configure a proxy when you initialize an SDK client by using the HttpClientConfig object. If you want to switch the proxy when you use the V1.0 SDK, use the ApacheHttpClient.getInstance().close()
code to close the current SDK client before you switch the proxy. The priority of the proxy that you configure when you initialize an SDK client is higher than the priority of the proxy that you configure by using environment variables.
public static void main(String[] args) {
// Configure the proxy when you initialize an SDK client.
HttpClientConfig clientConfig = HttpClientConfig.getDefault();
// Configure an HTTP proxy.
clientConfig.setHttpProxy("http://127.0.0.1:9898");
// Configure an HTTPS proxy.
clientConfig.setHttpsProxy("http://user:password@127.0.0.1:8989");
// Specify the addresses that do not require proxies.
clientConfig.setNoProxy("127.0.0.1,localhost");
IClientProfile profile = DefaultProfile.getProfile(regionId, accesskeyId, accesskeySecret);
profile.setHttpClientConfig(clientConfig);
DefaultAcsClient client = new DefaultAcsClient(profile);
}