[英]cURL curl_exec request is failing
我正在為一個項目和其他開發人員創建一個基於PHP的Google Webfont API。 這個腳本幾乎是一個,除了一個讓我感到悲傷的方法。
我有一個方法,使用cURL將現有的JSON字符串替換為來自Google的當前副本。
public function refreshFontList() {
if(empty($this->publicKey)) {
throw new Exception("API key cannot be empty", 1);
}
// cURL support is needed, test for cURL support before firing
if(!in_array("curl", get_loaded_extensions())) {
if(!init_get("allow_url_fopen")) {
die("Cannot get remote file");
}
} else {
echo "From Google\n";
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => "https://www.googleapis.com/webfonts/v1/webfonts?key=" . $this->publicKey,
CURLOPT_BINARYTRANSFER => TRUE, // for < PHP 5.1.3
CURLOPT_FAILONERROR => TRUE,
CURLOPT_FRESH_CONNECT => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => FALSE
)
);
var_dump(curl_exec($ch)); // shows as FALSE
curl_close($ch);
}
}
由於某些我不知道的原因, ch_exec()
函數無法捕獲對Google調用的API輸出,只是輸出boolean(false)
作為輸出。 為了更好地理解項目的范圍,這里有完整的課程: http : //tny.cz/d894e185 。
...
$output = curl_exec($ch);
var_dump($output); // still false
...
和
$this->setFontList(ch_exec($ch));
另外,我還禁用了我為curl_setopt_array
設置的所有選項,但沒有用。
非常感謝任何幫助!
嘗試使用:
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_SSL_VERIFYPEER => FALSE,
更多信息:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.