$ch = curl_init(); //$keyword='hello'; $url = 'http://apis.baidu.com/apistore/tranlateservice/dictionary?query=hello&from=en&to=zh'; $header = array( 'apikey: 這裡是我的apikey,我沒有寫', ); // 添加apikey到header curl_setopt($ch, CURLOPT_HTTPHEADER , $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 執行HTTP請求 curl_setopt($ch , CURLOPT_URL , $url); $res = curl_exec($ch); curl_close($ch); var_dump(json_decode($res));
回複內容:
$ch = curl_init(); //$keyword='hello'; $url = 'http://apis.baidu.com/apistore/tranlateservice/dictionary?query=hello&from=en&to=zh'; $header = array( 'apikey: 這裡是我的apikey,我沒有寫', ); // 添加apikey到header curl_setopt($ch, CURLOPT_HTTPHEADER , $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 執行HTTP請求 curl_setopt($ch , CURLOPT_URL , $url); $res = curl_exec($ch); curl_close($ch); var_dump(json_decode($res));
因為百度返回給你的結果就是空, 為 百度百度提供的調試工具 得到的結果, 和你提供的代碼所獲得到的結果是一樣的.