我正在为不存在的网站获取200响应

时间:2016-08-04 19:13:47

标签: php http curl

我正在尝试以下代码:

<?php
$site1 = 'http://www.teraasdsfssgggdadafasfra.com.br';

$handle = curl_init($site1);
curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);

/* Gets the HTML or whatever is linked in the $url. */
$response = curl_exec($handle);

/* Gets the HTTP code */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);

echo $httpCode;

curl_close($handle);
?>

正如您所看到的,URL非常奇怪,可能会返回404代码。

但是,我得到的代码是200响应,就像页面存在一样。

我想我可能会误解应该用来检查网页是否已启动的标准。我可能会在这里失踪什么?

谢谢。

1 个答案:

答案 0 :(得分:1)

回应阿布拉这样的事情 http://www.google.com存在 但jkshakl ...会给你预期的404错误

<?php
    $site1 = "http://www.google.com/jkdshaklfjhdasf";

$handle = curl_init($site1);
curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);

/* Gets the HTML or whatever is linked in the $url. */
if($response = curl_exec($handle)){

/* Gets the HTTP code */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);

echo $httpCode;

curl_close($handle); 

}

else echo "server does not exist";
?>