function cURL($url, $header=NULL, $p=NULL)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/TestCookies");
if ($p) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
}
$result = curl_exec($ch);
if ($result) {
return $result;
} else {
return curl_error($ch);
}
curl_close($ch);
}
而且我正在做這樣的電話...
$Headers = array(
"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*\/*;q=0.5",
"Accept-Language: en-gb,en;q=0.5",
"Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7");
$a = $this->cURL("https://www.mysite.com/",$Headers, null);
我d預計這會收到一個cookie並將其寫入文件/tmp/TestCookies
。
該網站肯定會返回Set-Cookie
標題 - 我可以看到它們,如果我轉儲$a
,但是,從未創建有問題的文件。
萬一它是一個權限問題,我用touch
和chmod 777
'd it創建了它 - 文件現在存在,但它是空的。
我在做什麼錯?
'_COOKIEFILE'被讀取,只有'_COOKIEJAR'被寫入。 – mario 2012-01-15 18:16:47
有點在這裏提到:http://stackoverflow.com/a/1861824/345031 – mario 2012-01-15 18:20:39
感謝您的信息 - 如果你想發佈它作爲答案,我會接受。 – Basic 2012-01-15 19:34:33