public function curl()
{
$this->channel = curl_init();
// you might want the headers for http codes
curl_setopt( $this->channel, CURLOPT_HEADER, true );
curl_setopt($this->channel, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
curl_setopt( $this->channel, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($this->channel, CURLOPT_VERBOSE, true);
curl_setopt($this->channel, CURLOPT_FAILONERROR, true);
curl_setopt($this->channel, CURLOPT_TIMEOUT,60);
curl_setopt( $this->channel, CURLOPT_RETURNTRANSFER, true );
curl_setopt($this->channel,CURLOPT_ENCODING,"gzip");
curl_setopt($this->channel, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->channel, CURLOPT_SSL_VERIFYPEER, 0);
}
我构建到web和错误:“对象移动到这里”,但我使用xampp localhost正在工作。
答案 0 :(得分:0)
您缺少更多卷曲执行的选项。例如exec, close, url
等。CURLOPT_URL
您在哪里不会初始化要发布的网址。还尝试删除重复的选项集。
public function curl() {
$url = 'your url';
$this->channel = curl_init($url);
// you might want the headers for http codes
curl_setopt( $this->channel, CURLOPT_HEADER, true );
curl_setopt($this->channel, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
curl_setopt( $this->channel, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($this->channel, CURLOPT_TIMEOUT,60);
curl_setopt( $this->channel, CURLOPT_RETURNTRANSFER, true );
curl_setopt($this->channel, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($this->channel, CURLOPT_SSL_VERIFYPEER, 0);
// Execute curl.
$result = curl_exec ($this->channel);
// Check what exectly curl is doing.
print_r(curl_getinfo($this->channel));
// CLOSE CURL
curl_close ($this->channel);
}
您可以在卷曲关闭之前通过curl_getinfo($this->channel)
检查您的卷曲执行信息。还为结果设置了输出。
答案 1 :(得分:0)
您可以设置回传卷曲选项。请查看 php_docs 了解更多信息。
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1)