200 HTTP CODE在非url字符串 [英] 200 HTTP CODE at non-url strings
问题描述
$agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch=curl_init();
curl_setopt ($ch, CURLOPT_URL,$url );
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,CURLOPT_VERBOSE,false);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch,CURLOPT_SSLVERSION,3);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
$page=curl_exec($ch);
//echo curl_error($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
我在我的项目中使用cUrl。我得到的HTTP网站的CODE。但是当我尝试asdasd($ url =asdasd),返回的HTTP CODE是200。但是asdasd不是一个网站。为什么HTTP CODE是200?
I'm using cUrl at my project. I'm getting HTTP CODE of web sites. But when i try "asdasd" ($url="asdasd") , returned HTTP CODE is 200 . But "asdasd" isn't a web site. Why HTTP CODE is 200 ?
推荐答案
您可能首先要检查 curl_exec
的返回值。它在手册中说:
You might want to check the return value from curl_exec
first. It says in the manual:
成功或
FALSE
返回TRUE
code> 。但是,如果设置了CURLOPT_RETURNTRANSFER
选项,则会返回成功结果FALSE
。
Returns
TRUE
on success orFALSE
on failure. However, if theCURLOPT_RETURNTRANSFER
option is set, it will return the result on success,FALSE
on failure.
对于 curl_getinfo
,有一个旁注:
如果重新使用句柄,则保留此函数收集的信息。这意味着,除非统计信息被此函数内部覆盖,否则将返回上一个信息。
Information gathered by this function is kept if the handle is re-used. This means that unless a statistic is overridden internally by this function, the previous info is returned.
因此HTTP 200可能是以前的cURL调用的结果。
So that HTTP 200 might well be the result of a previous cURL invocation.
这篇关于200 HTTP CODE在非url字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!