Home >php教程 >php手册 >PHP curl 获取响应的状态实例

PHP curl 获取响应的状态实例

WBOY
WBOYOriginal
2016-05-25 16:50:311232browse

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还可以获取很多其他信息.

教程地址:

欢迎转载!但请带上文章地址^^

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn