I would like to know how I can disable redirect for specific requests when using HttpClient. Right now, my client either allows or disables redirects for all its request. I want to be able to make some requests with redirects but some with redirect disable, all with the same client. Is it possible?
Example of using two clients (this is what I want to avoid):
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
public class MyClass {
public static void main(String[] args) throws Exception {
// Redirected client
CloseableHttpClient client = HttpClients.createDefault();
HttpGet get = new HttpGet("http://www.google.com");
client.execute(get);
// Non-redirected client
CloseableHttpClient client2 = HttpClientBuilder.create().disableRedirectHandling().build();
HttpGet get2 = new HttpGet("http://www.google.com");
client2.execute(get2);
}
}