您好,欢迎访问一九零五行业门户网

PHP curl 获取响应的状态实例

php curl可以从服务器端模拟一个http请求,例如抓取网页、模拟登陆等,根据选项设置,可以在curl_exec的返回结果中获取到响应头和body,但这没有响应的状态吗,想要获取状态吗,需要在执行curl_exec后再通过curl_getinfo来获取.
实例代码如下:
$ch = curl_init (); curl_setopt($ch, curlopt_url, 'http://www.phprm.com'); curl_setopt($ch, curlopt_timeout, 200); curl_setopt($ch, curlopt_header, false); curl_setopt($ch, curlopt_nobody, false); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_followlocation, false); curl_setopt($ch, curlopt_customrequest, 'get'); curl_exec($ch); $httpcode = curl_getinfo($ch,curlinfo_http_code);
另外curl_getinfo还可以获取很多其他信息.
教程地址:
欢迎转载!但请带上文章地址^^
其它类似信息

推荐信息