这是一个网站的官方API调用的例子,可是我运行该代码后出现“Fatal error: Uncaught exception 'Exception' with message 'Could not get reply: Could not resolve host: mtgox.com; Host not found' in C:\xampp\htdocs\bit\mtgox_offical_exam.php:31 Stack trace: #0 C:\xampp\htdocs\bit\mtgox_offical_exam.php(38): mtgox_query('0/info.php') #1 {main} thrown in C:\xampp\htdocs\bit\mtgox_offical_exam.php on line 31”的页面提示,请教大侠明示错误出在哪里怎么解决。我的XAMPP环境openssl和CURL都已开启。<?php   function mtgox_query($path, array $req = array()) { 
// API settings 
$key = 'f1b32549-ddfe-4b13-a9d4-4dfa85c243e4'; 
$secret = 'v3Pln9ooyUaiLHxDsF8Sw785OUSYcZrM9oBNC+QWCOvNdxddiQ0brZMQR285ROtisTJa+h4TDfDn7Q2ZidN4aQ==';   

// generate a nonce as microtime, with as-string handling to avoid problems with 32bits systems 
$mt = explode(' ', microtime()); 
$req['nonce'] = $mt[1].substr($mt[0], 2, 6);   

// generate the POST data string 
$post_data = http_build_query($req, '', '&');   

// generate the extra headers 
$headers = array( 'Rest-Key: '.$key, 'Rest-Sign: '.base64_encode(hash_hmac('sha512', $post_data, base64_decode($secret), true)), );   

// our curl handle (initialize if required) 
static $ch = null; 
if (is_null($ch)) { 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')'); 

curl_setopt($ch, CURLOPT_URL, 'https://mtgox.com/api/'.$path); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);   

// run the query 
$res = curl_exec($ch); 
if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch)); 
$dec = json_decode($res, true); 
if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and requested API exists'); 
return $dec; 
}   

// example 1: get infos about the account, plus the list of rights we have access to 
var_dump(mtgox_query('0/info.php'));   
// old api (get funds) 
//var_dump(mtgox_query('0/getFunds.php'));   
// trade example 
// var_dump(mtgox_query('0/buyBTC.php', array('amount' => 1, 'price' => 15)));

?>

解决方案 »

  1.   

    APACHE、PHP集成环境是XAMPP 1.7.4
      

  2.   

    你好 你的API是从哪里下载的?
      

  3.   

    if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch)); 
    通过异常消息可知错误是域名解析的问题,这个网站在我这是正常的,可能是你的运行机器断网了,或者是DNS的问题