我遇到了freebase MQL登錄服務的問題。我正在發佈一個請求,然後freebase api應該發回頭文件,然後我將分析並獲取信息。cURL和Freebase的Api
但我得到的只有頭是HTTP/1.0 200 OK
代碼
class myFreebaseClass {
....
function doLogin() {
echo $uri = "http://".$this->config['apiSandboxHost'].'/'.$this->config['apiLoginPath'].'username='.$this->config['apiLoginUser'].'&password='.$this->config['apiLoginPass'];
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$this,'readHeader'));
$output = curl_exec($ch);
curl_close($ch);
}
function readHeader($ch, $string)
{
echo "Header: ".$string."<Br />";
if(strpos($string, 'Set-Cookie') !== false) {
$this->authCookies[] = str_replace('Set-Cookie: ', '', $string);
}
return true;
}
}
輸出
http://sandbox.freebase.com/api/account/login?username=dXXXXX&password=XXXX
Header: HTTP/1.0 200 OK
我在做什麼錯?我錯誤地獲取標題?
在此先感謝!
'$ this'是什麼?你在一個物體裏面嗎?我不完全明白你在那裏做什麼(但是,我從來沒有使用HEADERFUNCTION,所以它可能是我)。手冊中提到'回調函數的名稱需要兩個參數',所以我不明白你爲什麼要指定一個數組? – 2010-09-06 17:40:00
是的,所有的代碼都在一個類中,$ this這個數組的原因是它在這個類中調用了readHeader。沒有它,它將是一個未定義的函數。 – Lizard 2010-09-06 17:44:05
啊,當然。所以'readHeader'確實在你上面引用的函數之外?我確定它是,但排除它是某種語言/結構怪癖而不是CURL問題的可能性。 – 2010-09-06 17:55:35