回复内容: $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));
因为百度返回给你的结果就是空, 下图为 百度百度提供的调试工具 得到的结果, 和你提供的代码所获得到的结果是一样的.
