我正在使用此代码从互联网获取页面,但我得到的结果状态0:
$url='http://www.jiwlp.com';
$this->url = $url;
if (isset($this->url)) {
// start cURL instance
$this->ch = curl_init ();
// this tells cUrl to return the data
curl_setopt ($this->ch, CURLOPT_RETURNTRANSFER, 1);
// set the url to download
curl_setopt ($this->ch, CURLOPT_URL, $this->url);
// follow redirects if any
curl_setopt($this->ch,CURLOPT_FOLLOWLOCATION, true);
// tell cURL if the data is binary data or not
curl_setopt($this->ch, CURLOPT_BINARYTRANSFER, $this->binary);
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($this->ch, CURLOPT_VERBOSE, 1);
curl_setopt($this->ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 5);
// grabs the webpage from the internet
$this->html = curl_exec($this->ch);
$this->status = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
print_r(curl_getinfo($this->ch)); // closes the connection
curl_close ($this->ch);
}
我做错了什么?
4条答案
按热度按时间but5z9lq1#
这个版本为我工作,删除了oo
kcugc4gi2#
响应状态已经存储在
$this->status
中,我假设您指的是HTTP响应状态代码,因此,请尝试打印
$this->status
。kuuvgm7e3#
在php禁用函数中检查CURL。
如果CURL_EXEC在网络服务器中被禁用,php将不会给予错误,而是将[http_code] =〉0 header_size] =〉0 ....
从一个php页面运行phpinfo()是一种获取被禁用php函数列表的方法。
t5fffqht4#
我使用这个函数来获取http站点/链接状态: