Q:

HTTPClient redirect when using POST method

I have a site that redirect me to another site with this php code:
<?php
    header("Location: new.php?id=".$_POST["id"]."&test=".rand(5,15));
    echo "35";
?>

-new.php
<?php
    echo "ID: ".$_GET["id"]."| TEST: ".$_GET["test"];
?>

If I try to send a Post request with the HTTPClient, the site doesn't redirects me to the other site (response of the post request is 35). It works perfectly fine when I send a Get request. the response of the request is ID: | TEST: 13.
-http.java
public class Http {
    public static void main(String[] args) {
        HttpResponse response;
        CloseableHttpClient client = HttpClients.createDefault();

        HttpPost post = new HttpPost("http://localhost/test.php");
        try {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
            nameValuePairs.add(new BasicNameValuePair("id","55"));
            post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            response = client.execute(post);
            BufferedReader rd = new BufferedReader(new InputStreamReader(
                    response.getEntity().getContent()));
            String line = "";
            while ((line = rd.readLine()) != null) {
                System.out.println(line);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            HttpGet get = new HttpGet("http://localhost/test.php");
            response = client.execute(get);
            BufferedReader rd = new BufferedReader(new InputStreamReader(
                    response.getEntity().getContent()));
            String line = "";
            while ((line = rd.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

A:

Automatically redirecting POST requests is against RFC standards. Therefor, the HttpClient will not do this by default. However, according to the API of the DefaultRedirectStrategy this can be achieved by using the LaxRedirectStrategy.
In code this would look something like:
  DefaultHttpClient httpClient = new DefaultHttpClient();
  httpClient.setRedirectStrategy(new LaxRedirectStrategy());
  httpClient.execute(request);

