Home  >  Article  >  Backend Development  >  PHP curl gets the status instance of the response_PHP tutorial

PHP curl gets the status instance of the response_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:57:36968browse

PHP curl can simulate an http request from the server side, such as crawling web pages, simulating login, etc. Depending on the option settings, the response header and body can be obtained in the return result of curl_exec, but does this have no response status? If you want to get the status, you need to get it through curl_getinfo after executing curl_exec.

For example:

$ch = curl_init ();
curl_setopt($ch, CURLOPT_URL, 'http://www.bKjia.c0m');
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');
The code is as follows
 代码如下 复制代码

$ch = curl_init ();
curl_setopt($ch, CURLOPT_URL, 'http://www.bKjia.c0m');
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);

Copy code

curl_exec($ch);

$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);

In addition, curl_getinfo can also obtain a lot of other information http://www.bkjia.com/PHPjc/631497.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/631497.htmlTechArticlePHP curl can simulate an http request from the server side, such as grabbing web pages, simulating login, etc. Depending on the option settings, the response header and body can be obtained in the return result of curl_exec, but this...
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