I wrote a Java client which executes http GET requests without any problem.
Now I want to modify this client in order to execute https GET requests.
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
private String executeGet(final String url, String proxy, int port)
throws IOException, RequestUnsuccesfulException, InvalidParameterException {
CloseableHttpClient httpclient = null;
String ret = "";
RequestConfig config;
try {
String hostname = extractHostname(url);
logger.info("Hostname {}", hostname);
HttpHost target = new HttpHost(hostname, 80, null);
HttpHost myProxy = new HttpHost(proxy, port, "http");
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
AuthScope.ANY,
new UsernamePasswordCredentials(USERNAME, PASSWORD));
httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
config = RequestConfig.custom().setProxy(myProxy).build();
HttpGet request = new HttpGet(url);
request.setConfig(config);
CloseableHttpResponse response = httpclient.execute(target, request);
...
I was expecting an easy modification like using HttpsGet instead of HttpGet but no, there is no HttpsGet class available.
What is the easiest way to modify this method in order to handle https GET requests?