Does the Apache HttpClient handle GET requests differently compared to java.net.HttpURLConnection?
I tried making a GET request to a URL which returns a redirect using both methods. While the response code from HttpURLConnection returns a 302 as expected, making the same call using HttpClient results in a 200.
Below is my code:
// Using Apache HttpClient
HttpClient client = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
HttpGet request = new HttpGet(authUrl);
HttpResponse response = client.execute(request);
int responseCode = response.getStatusLine().getStatusCode(); //Returns 200
// Using java.net.HttpURLConnection
URL obj = new URL(authUrl);
HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
int responseCode = conn.getResponseCode(); //Returns 302
This is my first time using Apache HttpClient, so my code might be wrong.
Thanks.
for (Header header : response.getHeaders("Location")) { redirectLink = header.getValue(); }