我正在尝试在 Google App Engine Go 中实现以下 PHP 代码:<?phpfunction api_query(array $req = array()) { $key = '90294318da0162b082c3d27126be80c3873955f9'; $req['method'] = 'getinfo'; $req['nonce'] = 1394503747386411; // generate the POST data string $post_data = http_build_query($req, '', '&'); $sign = '75da1e3ff750286bf73d03197f1b779fbfff963fd7402941ae326509a6615eacb839b44f236b4d5ee6cff39321e7b35e9563a9a2075e99df0f4ee3b732999348'; // generate the extra headers $headers = array( 'Sign: '.$sign, 'Key: '.$key, ); // 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; Cryptsy API PHP client; '.php_uname('s').'; PHP/'.phpversion().')'); } curl_setopt($ch, CURLOPT_URL, 'https://api.cryptsy.com/api'); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 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'); echo "<pre>".print_r($dec, true)."</pre>"; return $dec;}我收到一条错误消息,提示“无法授权请求 - 检查您的发布数据”。有没有人看到可能导致此错误的原因?目前我最好的猜测是 Go 中的请求头可能是一个 map[string][]string,而在 PHP 中它似乎是一个数组......
2 回答
- 2 回答
- 0 关注
- 199 浏览
添加回答
举报
0/150
提交
取消