title: Checking content type from URL
body: <p>I asked this <a href="https://stackoverflow.com/q/27978778/3922207">question</a> before and <a href="https://stackoverflow.com/users/1831293/evgeniy-dorofeev">Evgeniy Dorofeev</a> answered it. Although worked for direct link only, but I accepted his answer. He just told me about check the content type from direct link:</p>
  
  <pre><code>String requestUrl = "https://dl-ssl.google.com/android/repository/android-14_r04.zip";
  URL url = new URL(requestUrl);
  URLConnection c = url.openConnection();
  String contentType = c.getContentType();
  </code></pre>
  
  <p>As far I know, there are two <code>URL</code> types to download a file:</p>
  
  <ul>
  <li><strong>Direct link</strong>. For example: <a href="https://dl-ssl.google.com/android/repository/android-14_r04.zip" rel="nofollow noreferrer">https://dl-ssl.google.com/android/repository/android-14_r04.zip</a>. From this link, we can download data directly and get the file name, included with file extension (in this link, <code>.zip</code> extension). So we can know what file to be downloaded. You can try to download from that link.</li>
  <li><strong>Undirect link</strong>. For example: <a href="http://www.example.com/directory/download?file=52378" rel="nofollow noreferrer">http://www.example.com/directory/download?file=52378</a>. Have you ever tried to download data from Google Drive? When downloading data from Google Drive, it will gives you an undirect link, such as the link above. We never know whether the link contains a file or webpage. Also, we don't know the file name and file extension is, because of this link type is unclear and random.</li>
  </ul>
  
  <p>I need to check whether it is a file or webpage. I must download it if the content type is a file.</p>
  
  <p>So my question:</p>
  
  <ul>
  <li><em>How do I check the content type from an undirect link?</em></li>
  <li><em>As shown in the comments of this question, can HTTP-redirects solves the problem?</em></li>
  </ul>
  
  <p>Thanks for your help.</p>