I already did something like this in PHP, but I need it in Java. This is my actual PHP code:
$error = false;
$ch = curl_init();
$options = array(
CURLOPT_URL => "http://google.com/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => "",
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_MAXREDIRS => 10,
);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch);
$headers = substr($response, 0, $httpCode['header_size']);
if(stripos($headers, 'X-Frame-Options: DENY') > -1 ||
stripos($headers, 'X-Frame-Options: SAMEORIGIN')) {
$error = true;
}
curl_close($ch);
So $error
is false
, but when webpage has set to disable embedding in iframe, it will set to true
, so I know, that this webpage is not embeddable.
All I have in Java is this:
HttpURLConnection con = (HttpURLConnection) new URL("http://google.com/").openConnection();
What I have to do in Java to get same results as in PHP?