fork download
  1. import org.apache.http.HttpRequest;
  2. import org.apache.http.HttpResponse;
  3. import org.apache.http.ProtocolException;
  4. import org.apache.http.client.HttpClient;
  5. import org.apache.http.impl.client.DefaultRedirectStrategy;
  6. import org.apache.http.impl.client.HttpClients;
  7. import org.apache.http.protocol.HttpContext;
  8.  
  9. public class Main {
  10. public static void main(String[] args) {
  11. HttpClient httpClient = HttpClients.custom()
  12. .setRedirectStrategy(new DefaultRedirectStrategy() {
  13. @Override
  14. public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
  15. boolean isRedirected = super.isRedirected(request, response, context);
  16. if (!isRedirected) {
  17. int statusCode = response.getStatusLine().getStatusCode();
  18. if (statusCode == 301 || statusCode == 302) {
  19. return true;
  20. }
  21. }
  22. return isRedirected;
  23. }
  24. })
  25. .build();
  26. }
  27. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty