這是你如何解決這個問題的例子:
// Include the Auth string in the headers
// Together with the API version being used
$headers = array(
"Authorization: GoogleLogin auth=" . $auth,
"GData-Version: 3.0",
);
// Make the request
curl_setopt($curl, CURLOPT_URL, "http://docs.google.com/feeds/default/private/full");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
curl_close($curl);
// Parse the response
$response = simplexml_load_string($response);
// Output data
foreach($response->entry as $file)
{
//now you can do what ever if file type is a txt
//if($file->title =="txt")
// do something
else
// do soething
echo "File: " . $file->title . "<br />";
echo "Type: " . $file->content["type"] . "<br />";
echo "Author: " . $file->author->name . "<br /><br />";
}
我發現在捲曲「CURLOPT_HEADERFUNCTION」,讓您爲標題回調函數的一個選項,但你不能從回調內部取消請求。你會得到這樣的錯誤:「嘗試在良好的編程設計中關閉cURL句柄回調」 – Greg 2009-12-04 21:50:05
,不應該爲「正常」操作拋出異常,因爲通常異常在算法上是昂貴的。他們應該只適用於很少發生的操作,如錯誤或不正確的行爲。 – zmo 2012-05-27 16:35:53
要放棄從爲'CURLOPT_HEADERFUNCTION'或其他'CURLOPT_ * FUNCTION'選項定義的回調函數內下載響應流,請將您的回調函數返回爲'-1'。 – lafor 2013-07-03 10:39:46