【发布时间】:2011-06-08 22:54:36
【问题描述】:
我有这个功能:
function Connect($url, $post = 0, $postfields = '')
{
$ch = curl_init();
if($post > 0) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
}
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/joomla-cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/joomla-cookie.txt');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$exec = curl_exec($ch);
if($exec) { return $exec; } else { return 0; }
}
我这样称呼它Connect($host)
而且它总是返回 0...
【问题讨论】:
-
$host建议您发送 "google.com" ,其中所需的 url 是http://google.com,您使用的是什么? -
@Sabeen 我实际上用 https:// 发送它也许是因为 https:// 而不是 http:// ?因为“google.com”有效。