title: HttpClient getting status codes and follow redirects to get end page status code
body: <p>I'm going mad trying to get HttpClient to work the way I want it. It's all going over my head.</p>
  
  <p>All I want to do is provide a URL, the URL could point to web pages, .zip files, .doc files and redirects that end up at any of the above. I would then be able to print the final status code to the console. </p>
  
  <p>Can anyone please help me out here? So far I have(a mess of code after throwing everything at it):</p>
  
  <pre><code>DefaultHttpClient client = new DefaultHttpClient();
  
      client.setRedirectStrategy(new DefaultRedirectStrategy(){
          public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context)  {
              boolean isRedirect=false;
              try {
                  isRedirect = super.isRedirected(request, response, context );
              } catch (org.apache.http.ProtocolException e) {
                  System.out.println("what?");
                  e.printStackTrace();
              }
              if (!isRedirect) {
                  int responseCode = response.getStatusLine().getStatusCode();
                  System.out.println(responseCode);
                  if (responseCode == 301 || responseCode == 302) {
                      System.out.println("redirect");
                      return true;
                  }
              }
              return isRedirect;
          }
      });
  
      HttpHead test = new HttpHead("http://support.xbox.com/en-US/xbox-live/troubleshoot/game-play");
      HttpEntity httpEntity = null;
      try {
          HttpResponse response = client.execute(test);
          System.out.println(response.getStatusLine().getStatusCode());
      } catch (ClientProtocolException e) {
          // TODO Auto-generated catch block
          System.out.println(e);
          System.out.println("400");
      } catch (IOException e) {
          System.out.println("404");
          System.out.println(e);
      }
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>For this url: <a href="http://support.xbox.com/en-US/xbox-live/troubleshoot/game-play" rel="nofollow">http://support.xbox.com/en-US/xbox-live/troubleshoot/game-play</a> I'm getting 404. I would have expected 200.</p>
  
  <p>For <a href="http://www.google.com" rel="nofollow">http://www.google.com</a> I get a 200 as expected.</p>
  
  <p>For <a href="http://tinyurl.com/2tx" rel="nofollow">http://tinyurl.com/2tx</a> a tinyurl redirect to google.com I get a 200.</p>
  
  <p>I'm not sure what to make of my results. I just want to be able to test links to see if they are working or broken from an end users point of view.</p>